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

login
register
mail settings
Submitter Colin King
Date Nov. 4, 2012, 10:19 p.m.
Message ID <1352067590-11820-3-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/197100/
State Rejected
Headers show

Comments

Colin King - Nov. 4, 2012, 10:19 p.m.
From: Colin Ian King <colin.king@canonical.com>

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

Patch

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;
 }