From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: thomas.preston@codethink.co.uk,
Andrew Morton <akpm@linux-foundation.org>,
Petr Mladek <pmladek@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
geert+renesas@glider.be, Jonathan Corbet <corbet@lwn.net>,
tcharding <me@tobin.cc>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Linux List Kernel Mailing <linux-kernel@vger.kernel.org>,
ben.dooks@codethink.co.uk
Subject: Re: [PATCH 2/2] vsprintf: Stop using obsolete simple_strtoul()
Date: Tue, 11 Dec 2018 23:30:31 +0200 [thread overview]
Message-ID: <20181211213031.GF10650@smile.fi.intel.com> (raw)
In-Reply-To: <CAHk-=wiDkpCdOdEHeSHKVwr6d5RJdVn7mLZaJO-mZkR=7hYkCA@mail.gmail.com>
On Tue, Dec 11, 2018 at 10:19:08AM -0800, Linus Torvalds wrote:
> On Tue, Dec 11, 2018 at 10:05 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > I think it's slightly more complicated, I run the following test case on glibc:
> >
> > uint32_t hi, lo, t;
> >
> > sscanf("00fafafafa0d0b0b0b0c000000", "%8x%8x%x", &hi, &lo, &t);
> >
> > 64-bit:
> > HI: 00fafafa LO: fa0d0b0b (c000000)
> > 32-bit:
> > HI: 00fafafa LO: fa0d0b0b (ffffffff)
>
> But that's exactly the values my pseudo-code gets (well, my
> "pseudo-code obviously just said
>
> // Now do "sign" and range checking on val
>
> The three sub-parts are: "00fafafa" "fa0d0b0b" and "0b0c000000"
>
> and the third one encounters an overflow in "long" on 32-bit, so it
> turns into ~0.
>
> And yes, the 64-bit "long" in that third value gets truncated to
> "uint32" when written to "t" (which is wht that "0b" part just gets
> lost.
>
> And that's just because of historical C scanf behavior. There's no
> overflow checking in "int". Only in "long" and "long long".
Yes, that's what my test case showed.
So, whatever implementation would be done, I think it is a good time
to introduce some test cases.
P.S. I have briefly checked and didn't find a single test case for scanf().
Maybe I looked to the wrong module(s), but test_printf.c might be more or less a good choice.
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2018-12-11 21:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-11 15:21 [PATCH 0/2] vsprintf Stop using obsolete simple_strtoul() Thomas Preston
2018-12-11 15:21 ` [PATCH 1/2] vsprintf: Specify type for union val members Thomas Preston
2018-12-11 15:21 ` [PATCH 2/2] vsprintf: Stop using obsolete simple_strtoul() Thomas Preston
2018-12-11 17:22 ` Linus Torvalds
2018-12-11 18:04 ` Andy Shevchenko
2018-12-11 18:19 ` Linus Torvalds
2018-12-11 21:30 ` Andy Shevchenko [this message]
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=20181211213031.GF10650@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=ben.dooks@codethink.co.uk \
--cc=corbet@lwn.net \
--cc=geert+renesas@glider.be \
--cc=linux-kernel@vger.kernel.org \
--cc=me@tobin.cc \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.com \
--cc=thomas.preston@codethink.co.uk \
--cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).