mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Bartosz Golaszewski" <brgl@bgdev.pl>, "Arnd Bergmann" <arnd@kernel.org>
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] gpio: virtuser: avoid non-constant format string
Date: Fri, 19 Jul 2024 16:28:19 +0200	[thread overview]
Message-ID: <6eb7d811-5c0a-4d0a-84f4-57323fd794e0@app.fastmail.com> (raw)
In-Reply-To: <CAMRc=MexLwZqoc-ymuu3OSu5YXcqdmfLuX88kK0uR_6WqHgp_w@mail.gmail.com>

On Fri, Jul 19, 2024, at 16:10, Bartosz Golaszewski wrote:
>> diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c
>> index 0e0d55da4f01..c55b72e426c7 100644
>> --- a/drivers/gpio/gpio-virtuser.c
>> +++ b/drivers/gpio/gpio-virtuser.c
>> @@ -805,7 +805,7 @@ static int gpio_virtuser_dbgfs_init_line_attrs(struct device *dev,
>>                 return -ENOMEM;
>>
>>         data->ad.desc = desc;
>> -       sprintf(data->consumer, id);
>> +       sprintf(data->consumer, "%s", id);
>>         atomic_set(&data->irq, 0);
>>         atomic_set(&data->irq_count, 0);
>>
>> --
>> 2.39.2
>>
>
> I know this should not happen as the string is checked for length when
> it is set over configfs but while we're at it: maybe make it 100%
> correct by using snprintf(data->consumer, sizeof(data->consumer), ...?

Actually I now think this should just be

     strscpy(data->consumer, id);

There was never a reason to use sprintf() here at all.
strscpy() does both the correct size check and avoids
treating it as a format string.

      Arnd

  reply	other threads:[~2024-07-19 14:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-19 11:46 Arnd Bergmann
2024-07-19 14:10 ` Bartosz Golaszewski
2024-07-19 14:28   ` Arnd Bergmann [this message]
2024-07-19 14:29     ` Bartosz Golaszewski

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=6eb7d811-5c0a-4d0a-84f4-57323fd794e0@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®