Date: Mon, 17 Dec 2001 14:24:32 +0200 From: Ruslan Ermilov <ru@FreeBSD.org> To: "Andrey A. Chernov" <ache@nagual.pp.ru> Cc: Guido van Rooij <guido@gvr.org>, standards@FreeBSD.org Subject: Re: Recent POSIX.1-2001 implementation of strtol(3) breaks POLA (was: Re: cvs commit: src/etc/periodic/security 550.ipfwlimit 650.ip6fwlimit) Message-ID: <20011217142432.A83850@sunbay.com> In-Reply-To: <20011214230229.GA14380@nagual.pp.ru> References: <200112140858.fBE8wL596075@freefall.freebsd.org> <20011214115711.A34932@gvr.gvr.org> <20011214135243.B64853@sunbay.com> <20011214125438.A35615@gvr.gvr.org> <20011214142928.A69958@sunbay.com> <20011214154506.A79266@sunbay.com> <20011214230229.GA14380@nagual.pp.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011217142432.A83850>