diff options
author | Isamu Mogi <saturday6c@gmail.com> | 2014-07-28 07:49:55 -0500 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2014-07-28 09:29:18 -0500 |
commit | b9be82d438d5b3926dbe30c8296ca8c36e8eff52 (patch) | |
tree | 97d69a09921cba01040cff8ee1061025f9bc973a /libraries | |
parent | 524f15de1262d387ccd8075b68ed310ce5305068 (diff) | |
download | haskell-b9be82d438d5b3926dbe30c8296ca8c36e8eff52.tar.gz |
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
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/GHC/IO/FD.hs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libraries/base/GHC/IO/FD.hs b/libraries/base/GHC/IO/FD.hs index 7b30504f8e..1134e95f8d 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 |