Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Dec 2001 02:02:30 +0300
From:      "Andrey A. Chernov" <ache@nagual.pp.ru>
To:        Ruslan Ermilov <ru@FreeBSD.org>
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:  <20011214230229.GA14380@nagual.pp.ru>
In-Reply-To: <20011214154506.A79266@sunbay.com>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
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.

> 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.

> 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.

> 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.

-- 
Andrey A. Chernov
http://ache.pp.ru/

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?20011214230229.GA14380>