-----Original Message----- From: coreboot-bounces@coreboot.org [mailto:coreboot-bounces@coreboot.org] On Behalf Of jordan.crouse@amd.com Sent: Friday, April 25, 2008 9:52 AM To: coreboot@coreboot.org Cc: Jordan Crouse Subject: [coreboot] [patch 1/4] libpayload: Add the null terminator to theend of the duplicated string
Here's a chunk of patches fixing various bugs in libpayload. Content-Disposition: inline; filename=fix-strdup.patch
Signed-off-by: Jordan Crouse jordan.crouse@amd.com Index: libpayload/libc/string.c =================================================================== --- libpayload.orig/libc/string.c 2008-04-24 17:58:11.000000000 -0600 +++ libpayload/libc/string.c 2008-04-24 17:58:04.000000000 -0600 @@ -173,11 +173,12 @@ char *strdup(const char *s) { int n = strlen(s);
- char *p = malloc(n);
char *p = malloc(n + 1);
if (p != NULL) strncpy(p, s, n);
p[n] = 0;
It seems simpler to use strcpy here instead of strncpy and manual null termination, since strlen gave you the size already.
Either way I'll agree that something needed to be done.
Myles
Acked-by: Myles Watson mylesgw@gmail.com