[commit: ghc] ghc-8.2: base: Fix offset initialization of Windows hLock implementation (6ba1dd5)

git at git.haskell.org git at git.haskell.org
Sat Apr 22 02:29:13 UTC 2017


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

On branch  : ghc-8.2
Link       : http://ghc.haskell.org/trac/ghc/changeset/6ba1dd57c9bab29d66c0c8a892c867d4890e64e6/ghc

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

commit 6ba1dd57c9bab29d66c0c8a892c867d4890e64e6
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Fri Apr 21 12:10:33 2017 -0400

    base: Fix offset initialization of Windows hLock implementation
    
    The previous implementation swapped the buffer size with the byte to be
    set, essentially resulting in an uninitialized buffer.
    
    Test Plan: Validate on Windows
    
    Reviewers: austin, hvr
    
    Subscribers: rwbarton, thomie
    
    GHC Trac Issues: #13599
    
    Differential Revision: https://phabricator.haskell.org/D3478
    
    (cherry picked from commit e134af010bdd0d2a94fbfd68e0605dc55e1be3a8)


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

6ba1dd57c9bab29d66c0c8a892c867d4890e64e6
 libraries/base/GHC/IO/Handle/Lock.hsc | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libraries/base/GHC/IO/Handle/Lock.hsc b/libraries/base/GHC/IO/Handle/Lock.hsc
index 5608c18..ebb3ce4 100644
--- a/libraries/base/GHC/IO/Handle/Lock.hsc
+++ b/libraries/base/GHC/IO/Handle/Lock.hsc
@@ -45,7 +45,6 @@ import Foreign.Marshal.Utils
 import GHC.IO.FD
 import GHC.IO.Handle.FD
 import GHC.Ptr
-import GHC.Real
 import GHC.Windows
 
 #endif
@@ -123,7 +122,7 @@ lockImpl h ctx mode block = do
   FD{fdFD = fd} <- handleToFd h
   wh <- throwErrnoIf (== iNVALID_HANDLE_VALUE) ctx $ c_get_osfhandle fd
   allocaBytes sizeof_OVERLAPPED $ \ovrlpd -> do
-    fillBytes ovrlpd (fromIntegral sizeof_OVERLAPPED) 0
+    fillBytes ovrlpd 0 sizeof_OVERLAPPED
     let flags = cmode .|. (if block then 0 else #{const LOCKFILE_FAIL_IMMEDIATELY})
     -- We want to lock the whole file without looking up its size to be
     -- consistent with what flock does. According to documentation of LockFileEx
@@ -131,7 +130,7 @@ lockImpl h ctx mode block = do
     -- not an error", however some versions of Windows seem to have issues with
     -- large regions and set ERROR_INVALID_LOCK_RANGE in such case for
     -- mysterious reasons. Work around that by setting only low 32 bits.
-    fix $ \retry -> c_LockFileEx wh flags 0 0xffffffff 0x0 ovrlpd >>= \case
+    fix $ \retry -> c_LockFileEx wh flags 0 0xffffffff 0xffffffff ovrlpd >>= \case
       True  -> return True
       False -> getLastError >>= \err -> if
         | not block && err == #{const ERROR_LOCK_VIOLATION} -> return False



More information about the ghc-commits mailing list