[coreboot] [patch 1/4] libpayload: Add the null terminator to the end of the duplicated string

jordan.crouse at amd.com jordan.crouse at amd.com
Fri Apr 25 17:52:10 CEST 2008


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 at 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;
 	return p;
 }
 

-- 
Jordan Crouse
Systems Software Development Engineer 
Advanced Micro Devices, Inc.





More information about the coreboot mailing list