From: Steven Rostedt <rostedt@goodmis.org>
To: Richard Fitzgerald <rf@opensource.cirrus.com>
Cc: Petr Mladek <pmladek@suse.com>, <sergey.senozhatsky@gmail.com>,
<linux-kernel@vger.kernel.org>, <patches@opensource.cirrus.com>
Subject: Re: [PATCH] lib: vsprintf: Fix handling of number field widths in vsscanf
Date: Fri, 20 Nov 2020 11:16:46 -0500 [thread overview]
Message-ID: <20201120111646.0daee5a4@gandalf.local.home> (raw)
In-Reply-To: <59d43108-814e-4bf1-73f9-4994291abc05@opensource.cirrus.com>
On Fri, 20 Nov 2020 16:04:15 +0000
Richard Fitzgerald <rf@opensource.cirrus.com> wrote:
> > But yeah, we could very much have cp - startp > max_chars.
> >
>
> My code handles the prefix overflow, but I did it by having
> __parse_integer_limit() simply give 0 if max_chars <= 0.
Yeah, but if that's the intended result, then it needs to be commented as
such, and the comment needs to be fixed. Right now it's:
/*
* Convert non-negative integer string representation in explicitly given radix
* to an integer. The maximum number of characters to convert can be given.
* A character limit of INT_MAX is effectively unlimited since a string that
* long is unreasonable.
* Return number of characters consumed maybe or-ed with overflow bit.
* If overflow occurs, result integer (incorrect) is still returned.
*
* Don't you dare use this function.
*/
That comment needs to include: "If max_chars <= 0, then this returns zero.".
-- Steve
>
> So if the field width isn't enough for the prefix/leading '-' and at
> least one digit, subtracting the prefix length from the field length
> will give a max_chars <= 0. And you'll get a result of 0 as in your
> '%2li%9lx' test case.
>
> I thought this was nice because it didn't need to add code to check
> for the prefix overflow - it comes inherently from the loop in
> __parse_integer_limit(). But I'm willing to change
> __parse_integer_limit() to take an unsigned and add explicit checks for
> the prefix/'-' overflow cases.
next prev parent reply other threads:[~2020-11-20 16:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-16 14:32 Richard Fitzgerald
2020-11-20 11:05 ` Petr Mladek
2020-11-20 15:07 ` Steven Rostedt
2020-11-20 16:04 ` Richard Fitzgerald
2020-11-20 16:16 ` Steven Rostedt [this message]
2020-11-20 16:32 ` Petr Mladek
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=20201120111646.0daee5a4@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=pmladek@suse.com \
--cc=rf@opensource.cirrus.com \
--cc=sergey.senozhatsky@gmail.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
all inboxes | Powered by JetHome®