Skip to content

System call functions sometimes treat the last line in a multi-line command as a separate command #4769

@savemetenminutes

Description

@savemetenminutes

From manual page: https://php.net/function.exec


    function argon2idKey(string $password, string $salt): string
    {
        $innerCommand =
            'echo ' . escapeshellarg($password) . ' | \\' . "\n"
            . '  argon2 $(echo ' . escapeshellarg(base64_encode($salt)) . ' | base64 -d) -id -l 32 \\' . "\n"
            . '    -t 1 \\' . "\n"
            . '    -m 16 \\' . "\n"
            . '    -p 4 \\ ' . "\n"
            . '    -r';
        $command = 'bash -c ' . escapeshellarg($innerCommand);

        echo $command;

        return exec($command);
    }

The output contains "bash: line 6: -r: command not found". If the output of echo $command; is copied/pasted into the console and ran as-is, it will execute normally. If the -r argument is placed together with -p 4 becoming . ' -p 4 -r', exec() will execute the command with no issues.

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