mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Subject: Re: [PATCH] libfile: null-terminate buffer as expected
Date: Mon, 16 Sep 2019 20:48:13 +0200	[thread overview]
Message-ID: <f8e5f85c-2973-0c8a-080e-33a5254183b4@pengutronix.de> (raw)
In-Reply-To: <20190916183816.20300-1-a.fatoum@pengutronix.de>

On 9/16/19 8:38 PM, Ahmad Fatoum wrote:
> strim calls strlen on buf internally which is undefined because buf
> is not null-terminated. Fix this.

Please dismiss... read_file_2 has its buffer allocated with calloc,
thus nothing to see here...

> 
> Accessing buf+size is safe, because read_file_2 always allocates a
> 1 byte bigger buffer than the required (non-null-terminated) size.
> 
> This leading to errors can be observed by increasing the alignment of
> the buffer allocated in read_file_2. This would lead to
> 
> 	ERROR: Cannot init param from global: ... : Invalid argument
> 
> messages whenever nvvar_load is executed.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  lib/libfile.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/libfile.c b/lib/libfile.c
> index 172602377fc0..92f8fc2608e5 100644
> --- a/lib/libfile.c
> +++ b/lib/libfile.c
> @@ -136,6 +136,8 @@ char *read_file_line(const char *fmt, ...)
>  	if (!buf)
>  		goto out;
>  
> +	buf[size] = '\0';
> +
>  	line = strim(buf);
>  
>  	line = xstrdup(line);
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2019-09-16 18:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-16 18:38 Ahmad Fatoum
2019-09-16 18:48 ` Ahmad Fatoum [this message]
2019-09-17  7:49   ` Sascha Hauer

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=f8e5f85c-2973-0c8a-080e-33a5254183b4@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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