]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
2000-01-28 Roland McGrath <roland@baalperazim.frob.com>
authorRoland McGrath <roland@gnu.org>
Fri, 28 Jan 2000 23:23:52 +0000 (23:23 +0000)
committerRoland McGrath <roland@gnu.org>
Fri, 28 Jan 2000 23:23:52 +0000 (23:23 +0000)
* 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.

hurd/hurdselect.c

index 4e9bc39ac2cb6919375794cf1d857a7a6f23792c..4b31a90d686121f88806d1e3ed8a3d9cff924133 100644 (file)
@@ -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)