[PATCH 02/12] lib: fwts_stringextras: use strncpy, strncat instead of strcpy, strcat

Colin King colin.king at canonical.com
Sun Nov 4 22:19:40 UTC 2012


From: Colin Ian King <colin.king at canonical.com>

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/src/fwts_stringextras.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/lib/src/fwts_stringextras.c b/src/lib/src/fwts_stringextras.c
index 0143477..91b4b1a 100644
--- a/src/lib/src/fwts_stringextras.c
+++ b/src/lib/src/fwts_stringextras.c
@@ -50,13 +50,15 @@ char *fwts_realloc_strcat(char *orig, const char *newstr)
 	size_t newlen = strlen(newstr);
 
 	if (orig) {
-		if ((orig = realloc(orig, strlen(orig) + newlen + 1)) == NULL)
+		newlen += strlen(orig) + 1;
+		if ((orig = realloc(orig, newlen)) == NULL)
 			return NULL;
-		strcat(orig, newstr);
+		strncat(orig, newstr, newlen);
 	} else {
-		if ((orig = malloc(newlen + 1)) == NULL)
+		newlen++;
+		if ((orig = malloc(newlen)) == NULL)
 			return NULL;
-		strcpy(orig, newstr);
+		strncpy(orig, newstr, newlen);
 	}
 	return orig;
 }
-- 
1.7.10.4




More information about the fwts-devel mailing list