Thread (39 messages) flat view 39 messages, 14 authors, 2016-06-15

Re: [msysGit] Re: [PATCH] compat: Add another rudimentary poll() emulation

From: Albert Dvornik <hidden>
Date: 2016-06-15 22:48:52

On Thu, May 27, 2010 at 9:06 AM, Erik Faye-Lund
[off-list ref] wrote:
[...]
But perhaps you should include a check along the lines of this:

if (nfds > FD_SETSIZE)
       return errno = EINVAL, error("poll: nfds must be below %d", FD_SETSIZE);

Just so we can know when the code fails :)
If you're checking against FD_SETSIZE (which is IMO a good idea), you
should consider that
(a) on the one system I'm aware of where fd_set doesn't use a bitmap
(Windows), FD_SETSIZE is a limit on the number of descriptors added to
the set, but
(b) on systems where fd_set uses a bitmap (i.e. Linux, perhaps all
UNIXes, etc), FD_SETSIZE is a limit on *each descriptor value*.  This
is also what POSIX says.

So on the latter systems, we want something like this before each FD_SET:

if (ufds[i].fd >= FD_SETSIZE) {
    errno = EINVAL;
    return error("poll: each fd must be below %d", FD_SETSIZE);
}

(The reason to have it in the loop, rather than just check maxfd
afterwards, is that FD_SET with an argument that's too big can trash
the stack.)

Of course, on Windows this would impose a limitation that all
descriptors be < 64, which is probably crazy.  Which means that you'd
have to actually distinguish the two types.  Sigh.

--bert
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help