[GHC] #7342: Bug in System.Posix.Env.putEnv
GHC
cvs-ghc at haskell.org
Thu Oct 18 00:25:59 CEST 2012
#7342: Bug in System.Posix.Env.putEnv
-----------------------------------------+----------------------------------
Reporter: SimonHengel | Owner:
Type: bug | Status: new
Priority: normal | Component: libraries/unix
Version: 7.4.2 | Keywords:
Os: Linux | Architecture: x86_64 (amd64)
Failure: Incorrect result at runtime | Testcase:
Blockedby: | Blocking:
Related: |
-----------------------------------------+----------------------------------
{{{putEnv}}} frees the marshaled string after calling {{{c_putenv}}}.
This leads to unpredictable behavior, as the string becomes part of the
environment and should not be freed.
See [http://pubs.opengroup.org/onlinepubs/007908799/xsh/putenv.html
SUSv2]:
> ... the string pointed to by string shall become part of the
> environment ...
The issue is reproducible with the following QC property:
{{{
import Test.QuickCheck
import Test.QuickCheck.Property
import System.Posix.Env
import Data.IORef
import qualified Data.Map as Map
import Control.Applicative
isValidKey :: String -> Bool
isValidKey k = '\NUL' `notElem` k && '=' `notElem` k && (not . null) k
isValidValue :: String -> Bool
isValidValue v = '\NUL' `notElem` v && (not . null) v
main :: IO ()
main = do
env' <- getEnvironment >>= newIORef . Map.fromList
quickCheck $ \k v -> isValidKey k ==> isValidValue v ==>
morallyDubiousIOProperty $ do
putEnv (k ++ "=" ++ v)
modifyIORef env' (Map.insert k v)
(==) <$> readIORef env' <*> (Map.fromList <$> getEnvironment)
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7342>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list