mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Jules Maselbas <jmaselbas@kalray.eu>
Cc: barebox@lists.infradead.org, Neeraj Pal <neerajpal09@gmail.com>
Subject: Re: [PATCH] common: console_common: Replace vsprintf with vsnprintf
Date: Wed, 12 May 2021 07:35:15 +0200	[thread overview]
Message-ID: <20210512053515.GK19819@pengutronix.de> (raw)
In-Reply-To: <20210417211144.26466-1-jmaselbas@kalray.eu>

Hi Jules,

On Sat, Apr 17, 2021 at 11:11:44PM +0200, Jules Maselbas wrote:
> Replace the *sprintf to their *snprintf version when printing
> to the fixed size printbuffer.
> 
> Reported-by: Neeraj Pal <neerajpal09@gmail.com>
> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> ---

I didn't realize you also created this patch. I like your version better
because of the sizeof() you used. Replaced my version with yours, but I
added the pbl/console.c changes from my patch to yours.

Sascha

>  common/console_common.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/common/console_common.c b/common/console_common.c
> index 3e0741572..dc3a611e1 100644
> --- a/common/console_common.c
> +++ b/common/console_common.c
> @@ -126,7 +126,7 @@ int pr_print(int level, const char *fmt, ...)
>  		return 0;
>  
>  	va_start(args, fmt);
> -	i = vsprintf(printbuffer, fmt, args);
> +	i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
>  	va_end(args);
>  
>  	pr_puts(level, printbuffer);
> @@ -139,18 +139,19 @@ int dev_printf(int level, const struct device_d *dev, const char *format, ...)
>  	va_list args;
>  	int ret = 0;
>  	char printbuffer[CFG_PBSIZE];
> +	size_t size = sizeof(printbuffer);
>  
>  	if (!IS_ENABLED(CONFIG_LOGBUF) && level > barebox_loglevel)
>  		return 0;
>  
>  	if (dev->driver && dev->driver->name)
> -		ret += sprintf(printbuffer, "%s ", dev->driver->name);
> +		ret += snprintf(printbuffer, size, "%s ", dev->driver->name);
>  
> -	ret += sprintf(printbuffer + ret, "%s: ", dev_name(dev));
> +	ret += snprintf(printbuffer + ret, size - ret, "%s: ", dev_name(dev));
>  
>  	va_start(args, format);
>  
> -	ret += vsprintf(printbuffer + ret, format, args);
> +	ret += vsnprintf(printbuffer + ret, size - ret, format, args);
>  
>  	va_end(args);
>  
> @@ -237,7 +238,7 @@ int printf(const char *fmt, ...)
>  	 * For this to work, printbuffer must be larger than
>  	 * anything we ever want to print.
>  	 */
> -	i = vsprintf (printbuffer, fmt, args);
> +	i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
>  	va_end(args);
>  
>  	/* Print the string */
> @@ -256,7 +257,7 @@ int vprintf(const char *fmt, va_list args)
>  	 * For this to work, printbuffer must be larger than
>  	 * anything we ever want to print.
>  	 */
> -	i = vsprintf(printbuffer, fmt, args);
> +	i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
>  
>  	/* Print the string */
>  	puts(printbuffer);
> @@ -344,7 +345,7 @@ int dprintf(int file, const char *fmt, ...)
>  	 * For this to work, printbuffer must be larger than
>  	 * anything we ever want to print.
>  	 */
> -	vsprintf(printbuffer, fmt, args);
> +	vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
>  	va_end(args);
>  
>  	/* Print the string */
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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 |

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


  reply	other threads:[~2021-05-12  5:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-17 21:11 Jules Maselbas
2021-05-12  5:35 ` Sascha Hauer [this message]
2021-05-12  7:17   ` Jules Maselbas

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=20210512053515.GK19819@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=jmaselbas@kalray.eu \
    --cc=neerajpal09@gmail.com \
    /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