Blame SOURCES/0080-Include-count-for-0-character-when-using-strncpy-to-.patch

3c4af5
From 7d90f7603af6b59e7144cef6617a1e9dd42161bd Mon Sep 17 00:00:00 2001
3c4af5
From: Jes Sorensen <jsorensen@fb.com>
3c4af5
Date: Mon, 18 May 2020 20:19:53 -0400
3c4af5
Subject: [PATCH 080/108] Include count for \0 character when using strncpy to
3c4af5
 implement strdup.
3c4af5
3c4af5
We have to include the \0 character in the length when copying a
3c4af5
string with strncpy() for which length was found with strlen().
3c4af5
Otherwise the destination will not get null terminated - except that
3c4af5
we explicitly zeroed it out earlier.
3c4af5
3c4af5
This quiets down the compiler's warnings.
3c4af5
3c4af5
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3c4af5
---
3c4af5
 dlink.c | 2 +-
3c4af5
 1 file changed, 1 insertion(+), 1 deletion(-)
3c4af5
3c4af5
diff --git a/dlink.c b/dlink.c
3c4af5
index 3efa94b..69aa7aa 100644
3c4af5
--- a/dlink.c
3c4af5
+++ b/dlink.c
3c4af5
@@ -63,7 +63,7 @@ char *dl_strndup(char *s, int l)
3c4af5
     if (s == NULL)
3c4af5
 	return NULL;
3c4af5
     n = dl_newv(char, l+1);
3c4af5
-    strncpy(n, s, l);
3c4af5
+    strncpy(n, s, l+1);
3c4af5
     n[l] = 0;
3c4af5
     return n;
3c4af5
 }
3c4af5
-- 
3c4af5
2.7.5
3c4af5