From: Roland McGrath Date: Fri, 28 Jan 2000 23:23:52 +0000 (+0000) Subject: 2000-01-28 Roland McGrath X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8312fb7e4f14bf26f481738d9fff8a99e33ab75c;p=thirdparty%2Fglibc.git 2000-01-28 Roland McGrath * hurd/hurdselect.c (_hurd_select): Don't allocate D as a variable-sized automatic. Instead, use alloca after capping number of elements (NFDS) to a reasonable upper bound. --- diff --git a/hurd/hurdselect.c b/hurd/hurdselect.c index 4e9bc39ac2c..4b31a90d686 100644 --- a/hurd/hurdselect.c +++ b/hurd/hurdselect.c @@ -1,5 +1,5 @@ /* Guts of both `select' and `poll' for Hurd. - Copyright (C) 1991,92,93,94,95,96,97,98, 99 Free Software Foundation, Inc. + Copyright (C) 1991,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -60,7 +60,7 @@ _hurd_select (int nfds, mach_port_t io_port; int type; mach_port_t reply_port; - } d[nfds]; + } *d; sigset_t oset; if (sigmask && __sigprocmask (SIG_SETMASK, sigmask, &oset)) @@ -73,6 +73,8 @@ _hurd_select (int nfds, any locks. The second pass then only touches our own stack, and gets the port references. */ + d = __alloca (nfds * sizeof d[0]); + for (i = 0; i < nfds; ++i) if (pollfds[i].fd >= 0) { @@ -149,9 +151,15 @@ _hurd_select (int nfds, HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_dtable_lock); - if (nfds > _hurd_dtablesize) + if ((unsigned int) nfds > _hurd_dtablesize) nfds = _hurd_dtablesize; + /* This allocation must be here so we can cap NFDS + to a reasonable bound beforehand. Some callers + might give us huge values for NFDS, and we would + try an unreasonable stack allocation. */ + d = __alloca (nfds * sizeof d[0]); + /* Collect the ports for interesting FDs. */ firstfd = lastfd = -1; for (i = 0; i < nfds; ++i)