From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: Undefined behavior in atoi()
Date: Mon, 7 Nov 2011 22:44:04 -0500 [thread overview]
Message-ID: <20111108034404.GP132@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAOH62Ji7utffebihNd+UCgVurF+O2fSPSR3oeQJ3GRsS3Kf4zw@mail.gmail.com>
On Sun, Nov 06, 2011 at 11:28:41PM +0100, Pascal Cuoq wrote:
> On Sun, Nov 6, 2011 at 10:21 PM, Rich Felker <dalias@aerifal.cx> wrote:
>
> >
> > Thanks. How did you manage to find this bug? Just browsing source?
> >
>
> I was looking at implementations for strtod() (long story for another time)
It should be noted that the current implementation is not correct.
There's lots of loss-of-precision.
> and I noticed that this library was the most pleasant C code I had
> seen in months (seriously), so I lingered a bit. So, the straightforward
> answer is "yes, code review".
Glad to hear you found the code pleasant, at least that part. Some
things (like floating point in vfprintf.c) are a bit ugly.. :)
> The slightly longer answer is that I have done the formal verification of
> "string to number" C functions in the past, found that they were correct,
> noticed the opposite trick, and somehow the relationship
> between the two clicked. So I was looking for a classic pitfall here.
Interesting, I'd never come across this one.
> Since my previous e-mail, I have been analyzing a few more cases for fun,
> and musl's original code also has this issue for the 40 or so values
> below LONG_MAX.
>
> The problem is then:
>
> src/stdlib/atol.orig.c:14:[kernel] warning: Signed overflow.
> assert (long)((long)10*n)+(long)*tmp_0 ≤
> 9223372036854775807LL;
>
> That is, you should in any case subtract '0' from the digit before adding
> it in
> at line 14. In the case of atoll() on IA32, it will even be more efficient.
Thanks for catching that too. I'd certainly be glad to hear the
results of any more code review/testing you're up to doing. I've been
a little bit out of touch with working on musl lately due to being
very busy, but I'm reading the list/irc and making occasional
improvements. Development should speed up a lot in a month or so.
Rich
next prev parent reply other threads:[~2011-11-08 3:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-06 14:24 Pascal Cuoq
2011-11-06 21:21 ` Rich Felker
2011-11-06 22:28 ` Pascal Cuoq
2011-11-08 3:44 ` Rich Felker [this message]
2011-11-08 5:43 ` Pascal Cuoq
2011-11-08 14:12 ` Rich Felker
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=20111108034404.GP132@brightrain.aerifal.cx \
--to=dalias@aerifal.cx \
--cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).