On native Windows, I see two test failures:

FAIL: test-pselect
==================

Invalid nfd test... failed (invalid errno after negative nfds)
Invalid fd test... passed
Unconnected socket test... passed
Connected sockets test... passed
General socket test with fork... passed
Pipe test... passed
FAIL test-pselect.exe (exit status: 1)

FAIL: test-select
=================

Invalid nfd test... failed (invalid errno after negative nfds)
Invalid fd test... passed
Unconnected socket test... passed
Connected sockets test... passed
General socket test with fork... passed
Pipe test... passed
FAIL test-select.exe (exit status: 1)

Note that only the first test ("Invalid nfd test") fails.

For both functions, the implementation is Gnulib's override.
So, the fix is easy. It makes these two tests succeed.


2023-04-24  Bruno Haible  <br...@clisp.org>

        select, pselect: Fix test failure on native Windows.
        * lib/select.c (rpl_select): Fail if nfds is out-of-range.
        * lib/pselect.c (pselect): Likewise.

diff --git a/lib/pselect.c b/lib/pselect.c
index f5d21e1048..52d3837878 100644
--- a/lib/pselect.c
+++ b/lib/pselect.c
@@ -45,6 +45,12 @@ pselect (int nfds, fd_set *restrict rfds,
   sigset_t origmask;
   struct timeval tv, *tvp;
 
+  if (nfds < 0 || nfds > FD_SETSIZE)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
   if (timeout)
     {
       if (! (0 <= timeout->tv_nsec && timeout->tv_nsec < 1000000000))
diff --git a/lib/select.c b/lib/select.c
index 3d3efff3de..6b6ca4154c 100644
--- a/lib/select.c
+++ b/lib/select.c
@@ -279,8 +279,11 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set 
*xfds,
   int i, fd, rc;
   clock_t tend;
 
-  if (nfds > FD_SETSIZE)
-    nfds = FD_SETSIZE;
+  if (nfds < 0 || nfds > FD_SETSIZE)
+    {
+      errno = EINVAL;
+      return -1;
+    }
 
   if (!timeout)
     wait_timeout = INFINITE;




Reply via email to