diff --git a/Zend/zend_ini_parser.y b/Zend/zend_ini_parser.y index 748ccd2235a6d..e384d320cebfc 100644 --- a/Zend/zend_ini_parser.y +++ b/Zend/zend_ini_parser.y @@ -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"); } diff --git a/sapi/cli/tests/gh20871.phpt b/sapi/cli/tests/gh20871.phpt new file mode 100644 index 0000000000000..99b825eaae851 --- /dev/null +++ b/sapi/cli/tests/gh20871.phpt @@ -0,0 +1,29 @@ +--TEST-- +GH-20871: Bad error line and file for invalid "-d" arguments +--SKIPIF-- + +--FILE-- +&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 +)