From: Oleh Kravchenko <oleg@kaa.org.ua>
To: Pavel Machek <pavel@ucw.cz>
Cc: linux-leds@vger.kernel.org
Subject: Re: [PATCH 1/2] leds: mlxreg: Fix possible buffer overflow
Date: Tue, 3 Sep 2019 21:11:30 +0300 [thread overview]
Message-ID: <E8C449CE-405A-473F-9A2F-393070C0DA28@kaa.org.ua> (raw)
In-Reply-To: <20190903141231.GA8199@amd>
Hi Pavel,
3 вер. 2019 р. о 17:12 Pavel Machek <pavel@ucw.cz> пише:
>> On Tue 2019-09-03 15:50:19, Oleh Kravchenko wrote:
>> Error was detected by PVS-Studio:
>> V512 A call of the 'sprintf' function will lead to overflow of
>> the buffer 'led_data->led_cdev_name'.
>
> Are you sure this is correct fix? Will the name be always properly
> null terminated?
snprintf() always terminate string by NULL
> Pavel
>
>> +++ b/drivers/leds/leds-mlxreg.c
>> @@ -228,8 +228,8 @@ static int mlxreg_led_config(struct mlxreg_led_priv_data *priv)
>> brightness = LED_OFF;
>> led_data->base_color = MLXREG_LED_GREEN_SOLID;
>> }
>> - sprintf(led_data->led_cdev_name, "%s:%s", "mlxreg",
>> - data->label);
>> + snprintf(led_data->led_cdev_name, sizeof(led_data->led_cdev_name),
>> + "mlxreg:%s", data->label);
>> led_cdev->name = led_data->led_cdev_name;
>> led_cdev->brightness = brightness;
>> led_cdev->max_brightness = LED_ON;
>
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
Best regards,
Oleh Kravchenko
next prev parent reply other threads:[~2019-09-03 18:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-03 12:50 [PATCH 1/2] leds: mlxreg: Fix possible buffer overflow Oleh Kravchenko
2019-09-03 12:50 ` [PATCH 2/2] leds: ns2: Fix wrong boolean expression Oleh Kravchenko
2019-09-03 14:12 ` Pavel Machek
2019-09-03 16:00 ` Oleh Kravchenko
2019-09-03 18:50 ` Pavel Machek
2019-09-03 19:46 ` Oleh Kravchenko
2019-09-03 21:02 ` Oleh Kravchenko
2019-09-03 14:12 ` [PATCH 1/2] leds: mlxreg: Fix possible buffer overflow Pavel Machek
2019-09-03 18:11 ` Oleh Kravchenko [this message]
2019-09-07 19:36 ` Pavel Machek
2019-09-08 8:57 ` Oleh Kravchenko
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=E8C449CE-405A-473F-9A2F-393070C0DA28@kaa.org.ua \
--to=oleg@kaa.org.ua \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/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).