[commit: packages/base] ghc-7.8: reading/writing blocking FDs over FD_SETSIZE is broken (Partially Trac #9168) (566fa60)

git at git.haskell.org git at git.haskell.org
Wed Jul 2 18:28:27 UTC 2014


Repository : ssh://git@git.haskell.org/base

On branch  : ghc-7.8
Link       : http://ghc.haskell.org/trac/ghc/changeset/566fa608b0b98f4976370afbc635248929794ed9/base

>---------------------------------------------------------------

commit 566fa608b0b98f4976370afbc635248929794ed9
Author: Sergei Trofimovich <slyfox at gentoo.org>
Date:   Wed Jul 2 12:52:26 2014 -0500

    reading/writing blocking FDs over FD_SETSIZE is broken (Partially Trac #9168)
    
    Summary:
    libraries/base/cbits/inputReady.c had no limits on file descriptors.
    Add a limit as non-threaded RTS does.
    
    Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org>
    
    Test Plan: none
    
    Reviewers: austin, simonmar
    
    Reviewed By: austin, simonmar
    
    Subscribers: simonmar, relrod, carter
    
    Differential Revision: https://phabricator.haskell.org/D28
    
    (cherry picked from commit b0316cdb10fbd9eaca7ede28c7bb3eb19f7766bf)


>---------------------------------------------------------------

566fa608b0b98f4976370afbc635248929794ed9
 cbits/inputReady.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/cbits/inputReady.c b/cbits/inputReady.c
index 51f278f..dac9d9b 100644
--- a/cbits/inputReady.c
+++ b/cbits/inputReady.c
@@ -25,7 +25,11 @@ fdReady(int fd, int write, int msecs, int isSock)
 	int maxfd, ready;
 	fd_set rfd, wfd;
 	struct timeval tv;
-	
+        if ((fd >= (int)FD_SETSIZE) || (fd < 0)) {
+            /* avoid memory corruption on too large FDs */
+            errno = EINVAL;
+            return -1;
+        }
 	FD_ZERO(&rfd);
 	FD_ZERO(&wfd);
         if (write) {



More information about the ghc-commits mailing list