Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 1 Jan 2017 21:04:48 -0500
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: Edge case: strtol with base==1

On Sun, Jan 01, 2017 at 04:45:19AM -0600, Ryan Prichard wrote:
> Hi,
> 
> I noticed that musl's strtol function allows a base of 1 by parsing strings
> of only zeros.  With all other bases less than 0 or greater than 36, strtol
> fails and sets errno to EINVAL.
> 
> Is this an oversight?
> 
> Not that it especially *matters*, but my guess is that the behavior isn't
> POSIX conforming:
>  - POSIX defines valid "subject sequences" for bases of 0 and 2-36.
>  - "In other than the C or POSIX locale, additional locale-specific subject
> sequence forms may be accepted."
> 
> In the C locale, musl is accepting a subject sequence of all zeroes, which
> POSIX doesn't define for a base of 1.
> 
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtol.html

Indeed, I think you're right. ISO C does not specify the behavior when
the base is invalid (it's UB), but POSIX does impose an error
requirement. It's not clear that it requires other bases to be
unsupported, just that an error be produced if the base is
unsupported, but I think the right behavior is not to support a
nonsense "base 1".

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.