From 93234b4c76d8443a010aa2012d9df98e3f78ce03 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 24 Apr 2023 21:28:32 +0200 Subject: [PATCH] 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. --- ChangeLog | 6 ++++++ lib/pselect.c | 8 +++++++- lib/select.c | 9 ++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b71a766075..d94710855d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-04-24 Bruno Haible + + 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. + 2023-04-24 Bruno Haible ftell, ftello: Fix recognition of pipes on native Windows. diff --git a/lib/pselect.c b/lib/pselect.c index a1eca0c6a2..52d3837878 100644 --- a/lib/pselect.c +++ b/lib/pselect.c @@ -1,6 +1,6 @@ /* pselect - synchronous I/O multiplexing - Copyright 2011-2022 Free Software Foundation, Inc. + Copyright 2011-2023 Free Software Foundation, Inc. This file is part of gnulib. @@ -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 c24249822d..6b6ca4154c 100644 --- a/lib/select.c +++ b/lib/select.c @@ -1,7 +1,7 @@ /* Emulation for select(2) Contributed by Paolo Bonzini. - Copyright 2008-2022 Free Software Foundation, Inc. + Copyright 2008-2023 Free Software Foundation, Inc. This file is part of gnulib. @@ -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; -- 2.39.5