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

Myles Watson mylesgw at gmail.com
Fri Apr 25 18:32:39 CEST 2008



> -----Original Message-----
> From: coreboot-bounces at coreboot.org [mailto:coreboot-bounces at coreboot.org]
> On Behalf Of jordan.crouse at amd.com
> Sent: Friday, April 25, 2008 9:52 AM
> To: coreboot at 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 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;

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 at gmail.com>






More information about the coreboot mailing list