[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20181211213031.GF10650@smile.fi.intel.com>
Date: Tue, 11 Dec 2018 23:30:31 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: thomas.preston@...ethink.co.uk,
Andrew Morton <akpm@...ux-foundation.org>,
Petr Mladek <pmladek@...e.com>,
Steven Rostedt <rostedt@...dmis.org>, geert+renesas@...der.be,
Jonathan Corbet <corbet@....net>, tcharding <me@...in.cc>,
Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
Linux List Kernel Mailing <linux-kernel@...r.kernel.org>,
ben.dooks@...ethink.co.uk
Subject: Re: [PATCH 2/2] vsprintf: Stop using obsolete simple_strtoul()
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@...ux.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
Powered by blists - more mailing lists