Skip to content

Bad address when using relative cwd and setting env #219

Closed
@pbrisbin

Description

@pbrisbin

I started getting a Bad address error when executing processes after updating from lts-18.5 to lts-18.10, which brings process from v1.6.9.0 to v1.6.13.2. It seems to be related to setting cwd and env in the CreateProcess.

Everything works fine if you don't change env. You can touch env, if you don't change cwd too. You can change env and change cwd, but depending on what you are changing cwd to and how that affects the command. For example, cwd = /bin and a command of ./true works fine even when changing env. Unfortunately, I have not been able to narrow down the pattern in that last variability. Note that setting cwd to . (or the full path to .) does not count as "change" for this issue, but setting env to the result of getEnvironment does. Straight-forward, right?

So, there are a lot of different combinations that trigger it, but here is one minimal repro:

% tree
.
├── Main.hs
└── sub
    └── exe

1 directory, 2 files
% cat sub/exe
#!/bin/sh    
true
-- Main.hs
{-# LANGUAGE TypeApplications #-}

module Main where

import Prelude

import Control.Exception (SomeException, try)
import System.Environment (getEnvironment)
import System.Process

main :: IO ()
main = do
    currentEnv <- getEnvironment
    let cp = (proc "./exe" []) { cwd = Just "./sub", env = Just currentEnv }
    x <- try @SomeException $ withCreateProcess cp $ \_ _ _ -> waitForProcess
    print x

Works in 18.5, not in 18.10:

% stack --resolver lts-18.5 runhaskell Main.hs
Right ExitSuccess
% stack --resolver lts-18.10 runhaskell Main.hs
Left ./exe: createProcess: exec: failed (Bad address)

Note that it is indeed isolated to process: I can use 18.10 with an extra-dep of process-1.6.9.0 and the bug goes away. I'm just not showing it that way because it requires more setup to repro.

I experienced this in typed-process (using setWorkingDir and setEnv), but eventually found the bug to be here.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions