php-src/ext/standard/tests/misc/exec_basic1.phpt
Nikita Popov 7e339a335e Make null byte error a ValueError
Currently we treat paths with null bytes as a TypeError, which is
incorrect, and rather inconsistent, as we treat empty paths as
ValueError. We do this because the error is generated by zpp and
it's easier to always throw TypeError there.

This changes the zpp implementation to throw a TypeError only if
the type is actually wrong and throw ValueError for null bytes.
The error message is also split accordingly, to be more precise.

Closes GH-6094.
2020-09-08 15:23:23 +02:00

31 lines
808 B
PHP

--TEST--
exec, system, passthru Basic command execution functions
--SKIPIF--
<?php
// If this does not work for Windows, please uncomment or fix test
// if(substr(PHP_OS, 0, 3) == "WIN") die("skip not for Windows");
?>
--FILE--
<?php
$cmd = "echo abc\n\0command";
try {
var_dump(exec($cmd, $output));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump(system($cmd, $output));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump(passthru($cmd, $output));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECT--
exec(): Argument #1 ($command) must not contain any null bytes
system(): Argument #1 ($command) must not contain any null bytes
passthru(): Argument #1 ($command) must not contain any null bytes