linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Takashi Iwai <tiwai@suse.de>
Cc: Jean Delvare <jdelvare@suse.com>,
	linux-hwmon@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] hwmon: (ibmpowernv) Use scnprintf() for avoiding potential buffer overflow
Date: Wed, 11 Mar 2020 08:09:54 -0700	[thread overview]
Message-ID: <20200311150954.GA10207@roeck-us.net> (raw)

On Wed, Mar 11, 2020 at 08:39:44AM +0100, Takashi Iwai wrote:
> Since snprintf() returns the would-be-output size instead of the
> actual output size, the succeeding calls may go beyond the given
> buffer limit.  Fix it by replacing with scnprintf().
> 
> Signed-off-by: Takashi Iwai <tiwai@suse.de>

Applied to hwmon-next.

Thanks,
Guenter

> ---
>  drivers/hwmon/ibmpowernv.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
> index 0e525cfbdfc5..a750647e66a4 100644
> --- a/drivers/hwmon/ibmpowernv.c
> +++ b/drivers/hwmon/ibmpowernv.c
> @@ -186,7 +186,7 @@ static void make_sensor_label(struct device_node *np,
>  	u32 id;
>  	size_t n;
>  
> -	n = snprintf(sdata->label, sizeof(sdata->label), "%s", label);
> +	n = scnprintf(sdata->label, sizeof(sdata->label), "%s", label);
>  
>  	/*
>  	 * Core temp pretty print
> @@ -199,11 +199,11 @@ static void make_sensor_label(struct device_node *np,
>  			 * The digital thermal sensors are associated
>  			 * with a core.
>  			 */
> -			n += snprintf(sdata->label + n,
> +			n += scnprintf(sdata->label + n,
>  				      sizeof(sdata->label) - n, " %d",
>  				      cpuid);
>  		else
> -			n += snprintf(sdata->label + n,
> +			n += scnprintf(sdata->label + n,
>  				      sizeof(sdata->label) - n, " phy%d", id);
>  	}
>  
> @@ -211,7 +211,7 @@ static void make_sensor_label(struct device_node *np,
>  	 * Membuffer pretty print
>  	 */
>  	if (!of_property_read_u32(np, "ibm,chip-id", &id))
> -		n += snprintf(sdata->label + n, sizeof(sdata->label) - n,
> +		n += scnprintf(sdata->label + n, sizeof(sdata->label) - n,
>  			      " %d", id & 0xffff);
>  }
>  
> -- 
> 2.16.4
> 

             reply	other threads:[~2020-03-11 15:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11 15:09 Guenter Roeck [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-03-11  7:39 [PATCH] hwmon: (ibmpowernv) Use scnprintf() for avoiding potential buffer overflow Takashi Iwai

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=20200311150954.GA10207@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=tiwai@suse.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;
as well as URLs for NNTP newsgroup(s).