Skip to content

NUL byte disallowed in arguments #319

Description

@mmhat

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:

withMany withFilePath (cmd:args) $ \cstrs ->
(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 haskell/core-libraries-committee#144.

Activity

  1. mmhat commented on Jun 22, 2024

    @mmhat
    ContributorAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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