[commit: ghc] master: Avoid to pass a socket to setmode/isatty in Windows (b9be82d)

git at git.haskell.org git at git.haskell.org
Mon Jul 28 14:38:16 UTC 2014


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/b9be82d438d5b3926dbe30c8296ca8c36e8eff52/ghc

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

commit b9be82d438d5b3926dbe30c8296ca8c36e8eff52
Author: Isamu Mogi <saturday6c at gmail.com>
Date:   Mon Jul 28 07:49:55 2014 -0500

    Avoid to pass a socket to setmode/isatty in Windows
    
    Summary:
    In Windows, a socket is not a file descriptor. So passing it to
    setmode/isatty causes an error that returns EABF and triggers invalid
    parameter handler.
    
    Test Plan:
    1. Add WinDbg as a postmortem debugger (C:\>windbg -I)
    2. Pass a socket to GHC.IO.Device.IODevice.isTerminal / GHC.IO.FD.fdToHandle'  (Executing 'cabal update' calls each functions with the socket in cabal-install 1.20.0.1)
    3. WinDbg pops up and outputs error message: "Invalid parameter passed to C runtime function."
    4. Apply the patch
    5. Redo step 2
    6. WinDbg doesn't pop up
    
    Reviewers: austin
    
    Reviewed By: austin
    
    Subscribers: phaskell, simonmar, relrod, carter
    
    Differential Revision: https://phabricator.haskell.org/D92


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

b9be82d438d5b3926dbe30c8296ca8c36e8eff52
 libraries/base/GHC/IO/FD.hs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libraries/base/GHC/IO/FD.hs b/libraries/base/GHC/IO/FD.hs
index 7b30504..1134e95 100644
--- a/libraries/base/GHC/IO/FD.hs
+++ b/libraries/base/GHC/IO/FD.hs
@@ -261,7 +261,7 @@ mkFD fd iomode mb_stat is_socket is_nonblock = do
         _other_type -> return ()
 
 #ifdef mingw32_HOST_OS
-    _ <- setmode fd True -- unconditionally set binary mode
+    unless is_socket $ setmode fd True >> return ()
 #endif
 
     return (FD{ fdFD = fd,
@@ -414,7 +414,8 @@ foreign import ccall safe "fdReady"
 isTerminal :: FD -> IO Bool
 isTerminal fd =
 #if defined(mingw32_HOST_OS)
-    is_console (fdFD fd) >>= return.toBool
+    if fdIsSocket fd then return False
+                     else is_console (fdFD fd) >>= return.toBool
 #else
     c_isatty (fdFD fd) >>= return.toBool
 #endif



More information about the ghc-commits mailing list