mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] fdt: copy terminating '\0' in lstrcpy()
Date: Wed, 26 Jul 2023 13:43:09 +0200	[thread overview]
Message-ID: <20230726114309.GM18491@pengutronix.de> (raw)
In-Reply-To: <20230719181129.367413-1-enrico.scholz@sigma-chemnitz.de>

On Wed, Jul 19, 2023 at 08:11:29PM +0200, Enrico Scholz wrote:
> From: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> 
> On large string tables (>64K), a
> 
> |		fdt->strings = realloc(fdt->strings, fdt->str_size * 2);
> 
> operation is executed.  This 'realloc()' does not zero the memory so
> there is no guarantee that the strings will be terminated properly.
> 
> Modify 'lstrcpy()' so that it also copies the terminating '\0'.
> 
> Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> ---
>  drivers/of/fdt.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 01d7dc37439f..9d72fafd3669 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -302,15 +302,15 @@ static int lstrcpy(char *dest, const char *src)
>  	int len = 0;
>  	int maxlen = 1023;
>  
> -	while (*src) {
> -		*dest++ = *src++;
> +	do {
> +		*dest++ = *src;
>  		len++;
>  		if (!maxlen)
>  			return -ENOSPC;
>  		maxlen--;
> -	}
> +	} while (*src++);
>  
> -	return len;
> +	return len - 1;
>  }
>  
>  static void *memalign_realloc(void *orig, size_t oldsize, size_t newsize)
> -- 
> 2.41.0
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      reply	other threads:[~2023-07-26 11:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19 18:11 Enrico Scholz
2023-07-26 11:43 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230726114309.GM18491@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=enrico.scholz@sigma-chemnitz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox