bug-gnulib
[Top][All Lists]
Advanced

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

Re: poll: enable argument check


From: Bruno Haible
Subject: Re: poll: enable argument check
Date: Sun, 23 Apr 2017 03:26:39 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-72-generic; KDE/5.18.0; x86_64; ; )

Hi Paul,

> > -  if (nfd < 0)
> > +  if (nfd > TYPE_MAXIMUM (nfds_t) / 2)
> 
> This doesn't look right. What does TYPE_MAXIMUM (nfds_t) / 2 have to do with 
> anything?

TYPE_MAXIMUM (nfds_t) / 2 is good for a quick check against an out-of-bounds 
nfd.
POSIX [1] says that nfd is out-of-bounds if it is > getdtablesize().

> Plus, five lines later there's a comment that starts "Don't check 
> directly for NFD too large" and this seems to directly contradict the code 
> now.

This comment means that the code is a bit sloppy for nfd > getdtablesize().
IMO, this is OK for nfd < TYPE_MAXIMUM (nfds_t) / 2 because such values rarely
occur by accident. Whereas it's easy to pass -1 by mistake, which gets converted
to (nfds_t)-1.

> Plus, there's another "nfd < 0" in the WINDOWS_NATIVE case.

Oops. Thanks. I've corrected it now.

> How about the attached patch?

I disagree. It no longer catches the case nfd = (nfds_t)-1 quickly.

Bruno

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html




reply via email to

[Prev in Thread] Current Thread [Next in Thread]