[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <fae2751f6881bfc402a074e909be6a67ef9467df.camel@HansenPartnership.com>
Date: Tue, 22 Oct 2024 10:30:18 -0400
From: James Bottomley <James.Bottomley@...senPartnership.com>
To: Rasmus Villemoes <ravi@...vas.dk>, Andy Shevchenko
<andy.shevchenko@...il.com>
Cc: Jiri Slaby <jirislaby@...nel.org>, Bartosz Golaszewski <brgl@...ev.pl>,
Kees Cook <kees@...nel.org>, Andy Shevchenko <andy@...nel.org>, Andrew
Morton <akpm@...ux-foundation.org>, Greg KH <gregkh@...uxfoundation.org>,
linux-hardening@...r.kernel.org, linux-kernel@...r.kernel.org, Bartosz
Golaszewski <bartosz.golaszewski@...aro.org>, stable@...r.kernel.org
Subject: Re: [PATCH] lib: string_helpers: fix potential snprintf() output
truncation
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
Powered by blists - more mailing lists