haskell / process

Library for dealing with system processes
http://hackage.haskell.org/package/process
Other
85 stars 80 forks source link

NUL byte disallowed in arguments #319

Open mmhat opened 1 week ago

mmhat commented 1 week ago

The following program worked just fine when compiled with GHC <9.8:

module Main (main) where

import System.Process

main :: IO ()
main = callProcess "echo" ["foo\0bar"]

Compiled with GHC >=9.8 it outputs the following runtime error:

*** Exception: /usr/bin/echo: checkForInteriorNuls: invalid argument (FilePaths must not contain internal NUL code units.)

The reason is that process also treats the arguments as FilePath: https://github.com/haskell/process/blob/d74bba244d9d7c83b3a0ef5159b4e2e0fa7df07b/System/Process/Posix.hs#L139 (Linking to the POSIX implementation here since I am running Linux.) The System.Posix.Internals.withFilePath function referenced there checks for internal NULL characters since base >4.19 due to the accepted CLC propsal https://github.com/haskell/core-libraries-committee/issues/144.

mmhat commented 1 week ago

The Windows implementation uses Foreign.C.String.withCWString which seems the correct choice to me.