Fix select decoding with bogus (huge or negative) nfds.

We used to allocate and fetch bit arrays using a sanitized
length, but then iterate over them with "j < arg[0]" condition,
where arg[0] is not sanitized. This segfaults if arg[0] is huge
or negative. This change fixes this.

Add test/select.c to capture the case.

Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
test/select.c: make comment more understandable.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Truncate arg[0] to int in select decoding.

This matches kernel's behavior.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
More select decoding fixes

* desc.c (decode_select): Actually print arg[0] as int on entering
syscall.  When arg[0] is negative, do not attempt to fetch and decode
descriptor sets on entering syscall, kernel will reject it anyway.
On exiting syscall, stop checking descriptor sets as soon as all
returned descriptors are found.
Fix select decoding for glibc in _FORTIFY_SOURCE mode

glibc in _FORTIFY_SOURCE mode raises SIGABRT when descriptor greater
or equal to FD_SETSIZE is passed to FD_ISSET.  Select family syscalls,
however, can legitimately accept such descriptors.  To overcome this
limitation, we have to replace FD_ISSET with an equivalent that imposes
no such restrictions.

* desc.c (fd_isset): New function.
(decode_select): Use it instead of FD_ISSET.
Add a test for the latest select decoding fix

* test/select.c (main): Add a test for nfds larger than FD_SETSIZE.
Speed up and explain fd_isset()

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>