linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: Zach Brown <zach.brown@ni.com>,
	rpurdie@rpsys.net, j.anaszewski@samsung.com
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	nathan.sullivan@ni.com
Subject: Re: [PATCH] leds: do not overflow sysfs buffer in led_trigger_show
Date: Tue, 16 Aug 2016 22:39:56 +0200	[thread overview]
Message-ID: <57B37A1C.2070707@gmail.com> (raw)
In-Reply-To: <1471299614-10415-1-git-send-email-zach.brown@ni.com>

Hi Zach,

On 08/16/2016 12:20 AM, Zach Brown wrote:
> From: Nathan Sullivan <nathan.sullivan@ni.com>
>
> Per the documentation, use scnprintf instead of sprintf to ensure there
> is never more than PAGE_SIZE bytes of trigger names put into the
> buffer.
>
> Signed-off-by: Nathan Sullivan <nathan.sullivan@ni.com>
> Signed-off-by: Zach Brown <zach.brown@ni.com>
> ---
>   drivers/leds/led-triggers.c | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
> index c92702a..8668538 100644
> --- a/drivers/leds/led-triggers.c
> +++ b/drivers/leds/led-triggers.c
> @@ -81,21 +81,23 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
>   	down_read(&led_cdev->trigger_lock);
>
>   	if (!led_cdev->trigger)
> -		len += sprintf(buf+len, "[none] ");
> +		len += scnprintf(buf+len, PAGE_SIZE - len, "[none] ");
>   	else
> -		len += sprintf(buf+len, "none ");
> +		len += scnprintf(buf+len, PAGE_SIZE - len, "none ");
>
>   	list_for_each_entry(trig, &trigger_list, next_trig) {
>   		if (led_cdev->trigger && !strcmp(led_cdev->trigger->name,
>   							trig->name))
> -			len += sprintf(buf+len, "[%s] ", trig->name);
> +			len += scnprintf(buf+len, PAGE_SIZE - len, "[%s] ",
> +					 trig->name);
>   		else
> -			len += sprintf(buf+len, "%s ", trig->name);
> +			len += scnprintf(buf+len, PAGE_SIZE - len, "%s ",
> +					 trig->name);
>   	}
>   	up_read(&led_cdev->trigger_lock);
>   	up_read(&triggers_list_lock);
>
> -	len += sprintf(len+buf, "\n");
> +	len += scnprintf(len+buf, PAGE_SIZE - len, "\n");
>   	return len;
>   }
>   EXPORT_SYMBOL_GPL(led_trigger_show);
>

Thanks for the patch, applied.

-- 
Best regards,
Jacek Anaszewski

      reply	other threads:[~2016-08-16 20:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-15 22:20 [PATCH] leds: do not overflow sysfs buffer in led_trigger_show Zach Brown
2016-08-16 20:39 ` Jacek Anaszewski [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=57B37A1C.2070707@gmail.com \
    --to=jacek.anaszewski@gmail.com \
    --cc=j.anaszewski@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=nathan.sullivan@ni.com \
    --cc=rpurdie@rpsys.net \
    --cc=zach.brown@ni.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;
as well as URLs for NNTP newsgroup(s).