1
1
/*
2
2
* R : A Computer Language for Statistical Data Analysis
3
3
* (C) Copyright 2008-2011 Simon Urbanek
4
- * Copyright 2011-2022 R Core Team.
4
+ * Copyright 2011-2023 R Core Team.
5
5
*
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
@@ -816,6 +816,8 @@ SEXP mc_send_child_stdin(SEXP sPid, SEXP what)
816
816
void fdcopy (fd_set * dst , fd_set * src , int nfds )
817
817
{
818
818
FD_ZERO (dst );
819
+ if (nfds > FD_SETSIZE )
820
+ error ("file descriptor is too large for select()" );
819
821
for (int i = 0 ; i < nfds ; i ++ )
820
822
if (FD_ISSET (i , src )) FD_SET (i , dst );
821
823
}
@@ -847,7 +849,7 @@ SEXP mc_select_children(SEXP sTimeout, SEXP sWhich)
847
849
unsigned int k = 0 ;
848
850
while (k < wlen ) {
849
851
if (which [k ++ ] == ci -> pid ) {
850
- if (ci -> pfd > FD_SETSIZE )
852
+ if (ci -> pfd >= FD_SETSIZE )
851
853
error ("file descriptor is too large for select()" );
852
854
FD_SET (ci -> pfd , & fs );
853
855
if (ci -> pfd > maxfd ) maxfd = ci -> pfd ;
@@ -860,7 +862,7 @@ SEXP mc_select_children(SEXP sTimeout, SEXP sWhich)
860
862
}
861
863
} else {
862
864
/* not sure if this should be allowed */
863
- if (ci -> pfd > FD_SETSIZE )
865
+ if (ci -> pfd >= FD_SETSIZE )
864
866
error ("file descriptor is too large for select()" );
865
867
FD_SET (ci -> pfd , & fs );
866
868
if (ci -> pfd > maxfd ) maxfd = ci -> pfd ;
@@ -1061,7 +1063,11 @@ SEXP mc_read_children(SEXP sTimeout)
1061
1063
while (ci ) {
1062
1064
if (!ci -> detached && ci -> ppid == ppid ) {
1063
1065
if (ci -> pfd > maxfd ) maxfd = ci -> pfd ;
1064
- if (ci -> pfd >= 0 ) FD_SET (ci -> pfd , & fs );
1066
+ if (ci -> pfd >= 0 ) {
1067
+ if (ci -> pfd >= FD_SETSIZE )
1068
+ error ("file descriptor is too large for select()" );
1069
+ FD_SET (ci -> pfd , & fs );
1070
+ }
1065
1071
}
1066
1072
ci = ci -> next ;
1067
1073
}
0 commit comments