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

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

 



On Thu, May 27, 2010 at 9:06 AM, Erik Faye-Lund
<kusmabite@xxxxxxxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]