Re: [patch] atoi.3: Document return value on under/overflow as undefined

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Thomas,

On Mon, Dec 11, 2023 at 02:53:31AM -0800, Thomas Habets wrote:
> On Sun, 10 Dec 2023 23:47:19 +0000, Alejandro Colomar <alx@xxxxxxxxxx> said:
> > Yeah, I'm thinking in 50 years from now, assuming all implementations
> > have good intentions and don't want to break programs just because the
> > standard says they can.  Hopefully atoi(3) could be usable in half a
> > century; if the planet is still there.
> 
> Sure, one can lead by example. I wouldn't hold my breath that everyone
> follows, though. I definitely predict maintainers (cough, some BSDs,
> cough) saying "nobody should use ato*() anyway".

To that (very likely) response, I'd reply with:

	Then remove it from your libc.

I'm sure they'll then reply with something like

	"but the standard says the function should exist"

To which I have another reply:

	POSIX also specifies gets(3) as of the latest version
	(POSIX.1-2017), and everyone (rightly) removed it from libc.
	While atoi(3) doesn't produce such an obvious buffer overflow,
	it similarly invokes Undefined Behavior on conditions which the
	program can't control or prevent, which makes the function
	equally broken.

To which they may say:

	But it's not so broken to remove it.  It's just that the
	standard doesn't mandate to implement it in the sane way, so
	nobody did it.

Then I'd reply:

	Then go fix it.

At which point, they may get in an infinite loop, or just redirect to
/dev/null.

> > BTW, regarding your blog post about strtoul(3), I don't think it's so
> > hard to parse unsigned integers.  I couldn't reply to your blong without
> > logging in, but replied to the linked SO post:
> > <https://softwareengineering.stackexchange.com/a/449060/332848>
> 
> Ah, parse it twice to check. Yeah I'd not thought of that. Thanks. I'll add an
> update.

Great.  :)

Have a nice day,
Alex

-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux