[prev in list] [next in list] [prev in thread] [next in thread]
List: freebsd-standards
Subject: Re: Recent POSIX.1-2001 implementation of strtol(3) breaks POLA (was: Re: cvs commit: src/etc/period
From: Ruslan Ermilov <ru () FreeBSD ! ORG>
Date: 2001-12-17 12:24:32
[Download RAW message or body]
On Sat, Dec 15, 2001 at 02:02:30AM +0300, Andrey A. Chernov wrote:
> On Fri, Dec 14, 2001 at 15:45:07 +0200, Ruslan Ermilov wrote:
> >
> > In NetBSD and OpenBSD, strtol() doesn't set errno to EINVAL if the
> > subject is empty. In UnixWare, it does, but atoi(3), which is
> > implemented there using strtol() too, has a special hack to not
> > set errno to EINVAL in this case, and this is a documented
> > behavior.
>
> It seems that UnixWare does it in the semi-right way, but I don't think
> POSIX allows special atoi() errno handling, it just say that it is fullly
> equivalent to strtol() call.
>
No, it says "except for error handling".
> > Linux's strtol() doesn't set errno to EINVAL too, but their
> > test(1) utility works like this:
> >
> > $ /usr/bin/test "" -eq 0
> > /usr/bin/test: integer expression expected before -eq
>
> It seems that Linux test does it in the right way. Good news is that
> strtol()'s POSIX change find the bug.
>
I checked "test" article in POSIX, and the latter doesn't say
anything about this case. Obviously, "" shouldn't be treated
as a zero.
> > What's really broken in FreeBSD now is that the following:
> >
> > errno = 0;
> > atoi("");
> >
> > sets errno to [EINVAL], while it shouldn't. I think this
> > may break many things.
>
> I don't think so, just otherwise, it find the bugs in many things. If
> application is smart enough to handle errno, it MUST assume the POSIX
> "MAY" clause CAN happens.
>
Agreed.
> > So while the current behavior of strtol() is accepted by
> > POSIX, I suggest that we don't return [EINVAL] for an
> > empty subject case, as it's not required, and as could
> > be seen from the above in against POLA. This should
> > fix it.
>
> I disagree. Look at this from different perspective. F.e. 'test' will
> remains unfixed without strtol()'s change forever. strtol() position
> itself as input checking function and already does it in some ways. Adding
> yet one way seems logical, really " " is not "0". Moreover, if POSIX says
> MAY, any application which assumes otherwise is broken in portability
> sense and must be fixed. I mean 'test' or anything else will be found.
>
OK, I now agree with you; treating "" as zero is bogus, and should
be fixed whenever hit.
Cheers,
--
Ruslan Ermilov Oracle Developer/DBA,
ru@sunbay.com Sunbay Software AG,
ru@FreeBSD.org FreeBSD committer,
+380.652.512.251 Simferopol, Ukraine
http://www.FreeBSD.org The Power To Serve
http://www.oracle.com Enabling The Information Age
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic