From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Rasmus Villemoes <ravi@prevas.dk>,
Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Jiri Slaby <jirislaby@kernel.org>,
Bartosz Golaszewski <brgl@bgdev.pl>, Kees Cook <kees@kernel.org>,
Andy Shevchenko <andy@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Greg KH <gregkh@linuxfoundation.org>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
stable@vger.kernel.org
Subject: Re: [PATCH] lib: string_helpers: fix potential snprintf() output truncation
Date: Tue, 22 Oct 2024 10:30:18 -0400 [thread overview]
Message-ID: <fae2751f6881bfc402a074e909be6a67ef9467df.camel@HansenPartnership.com> (raw)
In-Reply-To: <87y12gp7xb.fsf@prevas.dk>
On Tue, 2024-10-22 at 15:46 +0200, Rasmus Villemoes wrote:
[...]
> - snprintf(buf, len, "%u%s %s", (u32)size,
> - tmp, unit);
> + if (j)
> + snprintf(buf, len, "%u.%03u %s", (u32)size,
> remainder, unit);
> + else
> + snprintf(buf, len, "%u %s", (u32)size, unit);
> }
> EXPORT_SYMBOL(string_get_size);
Where are you getting this from? The current statement you'd be
replacing is
return snprintf(buf, len, "%u%s%s%s%s", (u32)size, tmp,
(units & STRING_UNITS_NO_SPACE) ? "" : " ",
unit,
(units & STRING_UNITS_NO_BYTES) ? "" : "B");
The use of a tmp buffer prevents that having to be repeated.
If we had a way of specifying "ignore argument" I suppose we could
switch the format string on J and then only have a single statement.
Regards,
James
next prev parent reply other threads:[~2024-10-22 14:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-21 10:04 Bartosz Golaszewski
2024-10-21 10:05 ` Bartosz Golaszewski
2024-10-22 7:15 ` Jiri Slaby
2024-10-22 7:30 ` Bartosz Golaszewski
2024-10-22 9:18 ` Andy Shevchenko
2024-10-22 11:07 ` David Laight
2024-10-22 9:15 ` Andy Shevchenko
2024-10-22 13:46 ` Rasmus Villemoes
2024-10-22 14:30 ` James Bottomley [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-10-21 9:14 Bartosz Golaszewski
2024-10-21 9:25 ` Andy Shevchenko
2024-10-21 9:34 ` Greg KH
2024-10-21 9:36 ` Bartosz Golaszewski
2024-10-21 9:50 ` Greg KH
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=fae2751f6881bfc402a074e909be6a67ef9467df.camel@HansenPartnership.com \
--to=james.bottomley@hansenpartnership.com \
--cc=akpm@linux-foundation.org \
--cc=andy.shevchenko@gmail.com \
--cc=andy@kernel.org \
--cc=bartosz.golaszewski@linaro.org \
--cc=brgl@bgdev.pl \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ravi@prevas.dk \
--cc=stable@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®