Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Zend/zend_ini_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ static ZEND_COLD void ini_error(const char *msg)
error_buf_len = 128 + (int)strlen(msg) + (int)strlen(currently_parsed_filename); /* should be more than enough */
error_buf = (char *) emalloc(error_buf_len);

sprintf(error_buf, "%s in %s on line %" PRIu32 "\n", msg, currently_parsed_filename, zend_ini_scanner_get_lineno());
if (strcmp(currently_parsed_filename, "Unknown") == 0 && CG(ini_parser_unbuffered_errors)) {
sprintf(error_buf, "%s in INI command line parameter '-d'\n", msg);
} else {
sprintf(error_buf, "%s in %s on line %" PRIu32 "\n", msg, currently_parsed_filename, zend_ini_scanner_get_lineno());
}
} else {
error_buf = estrdup("Invalid configuration directive\n");
}
Expand Down
29 changes: 29 additions & 0 deletions sapi/cli/tests/gh20871.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
GH-20871: Bad error line and file for invalid "-d" arguments
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');

exec("$php -d 'foo=bar=asd' -r \"echo 'hello' . PHP_EOL;\" 2>&1", $output, $exit_code);
print_r($output);

echo "\n";

exec("$php -d 'foo=bar!asd' -r \"echo 'world' . PHP_EOL;\" 2>&1", $output2, $exit_code2);
print_r($output2);

?>
--EXPECTF--
Array
(
[0] => PHP: syntax error, unexpected '=' in INI command line parameter '-d'
[1] => hello
)

Array
(
[0] => PHP: syntax error, unexpected '!' in INI command line parameter '-d'
[1] => world
)
Loading