Browse Source

lib:Fix fd set size

On systems with RLIMIT_NOFILE < FD_SETSIZE, quagga 1.2.4 (and earlier) calls
select(2) with a fd set size larger than the allocated buffers, which can cause crashes.
Fixes bug #981
Robert Vogelgesang 11 months ago
parent
commit
b54de751ef
1 changed files with 3 additions and 2 deletions
  1. 3 2
      lib/thread.c

+ 3 - 2
lib/thread.c

@@ -531,7 +531,8 @@ thread_master_create ()
       return NULL;
     }
 
-  rv->fd_limit = (int)limit.rlim_cur;
+  rv->fd_limit = ((int)limit.rlim_cur < FD_SETSIZE ?
+		  (int)limit.rlim_cur : FD_SETSIZE);
   rv->read = XCALLOC (MTYPE_THREAD, sizeof (struct thread *) * rv->fd_limit);
   if (rv->read == NULL)
     {
@@ -1190,7 +1191,7 @@ thread_fetch (struct thread_master *m)
             timer_wait = timer_wait_bg;
         }
       
-      num = fd_select (FD_SETSIZE, &readfd, &writefd, &exceptfd, timer_wait);
+      num = fd_select (m->fd_limit, &readfd, &writefd, &exceptfd, timer_wait);
       
       /* Signals should get quick treatment */
       if (num < 0)