From 10591c909a15c64b21b8cfa47385ca6b36b67709 Mon Sep 17 00:00:00 2001 From: Khaled Alam Date: Sat, 10 Jan 2026 22:59:59 +0400 Subject: [PATCH 1/3] Fix GH-20871: Improve error message for invalid -d options --- Zend/zend_ini_parser.y | 6 +++++- sapi/cli/tests/gh20871.phpt | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 sapi/cli/tests/gh20871.phpt diff --git a/Zend/zend_ini_parser.y b/Zend/zend_ini_parser.y index 748ccd2235a6d..ff19be5235850 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 -d option on line 0\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..5c48909b9aad8 --- /dev/null +++ b/sapi/cli/tests/gh20871.phpt @@ -0,0 +1,18 @@ +--TEST-- +GH-20871: Bad error line and file for invalid "-d" arguments +--SKIPIF-- + +--FILE-- +&1", $output, $exit_code); +print_r($output); + +?> +--EXPECTF-- +Array +( + [0] => PHP: syntax error, unexpected '=' in -d option on line 0 + [1] => hello +) From 2dd463f6e4f67bd8d217325136bc2e1d19f29109 Mon Sep 17 00:00:00 2001 From: Khaled Alam Date: Sat, 10 Jan 2026 23:07:18 +0400 Subject: [PATCH 2/3] Fix GH-20871: Improve error messages for invalid -d command-line options --- sapi/cli/tests/gh20871.phpt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sapi/cli/tests/gh20871.phpt b/sapi/cli/tests/gh20871.phpt index 5c48909b9aad8..4d5d7948ee9cd 100644 --- a/sapi/cli/tests/gh20871.phpt +++ b/sapi/cli/tests/gh20871.phpt @@ -9,6 +9,11 @@ $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 @@ -16,3 +21,9 @@ Array [0] => PHP: syntax error, unexpected '=' in -d option on line 0 [1] => hello ) + +Array +( + [0] => PHP: syntax error, unexpected '!' in -d option on line 0 + [1] => world +) From 617edaf2b8d88981effa1f04ab6e9819c2a1ed33 Mon Sep 17 00:00:00 2001 From: Khaled Alam Date: Sun, 11 Jan 2026 04:58:17 +0400 Subject: [PATCH 3/3] Fix GH-20871: Improve error messages for invalid -d command-line options --- Zend/zend_ini_parser.y | 2 +- sapi/cli/tests/gh20871.phpt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Zend/zend_ini_parser.y b/Zend/zend_ini_parser.y index ff19be5235850..e384d320cebfc 100644 --- a/Zend/zend_ini_parser.y +++ b/Zend/zend_ini_parser.y @@ -206,7 +206,7 @@ static ZEND_COLD void ini_error(const char *msg) error_buf = (char *) emalloc(error_buf_len); if (strcmp(currently_parsed_filename, "Unknown") == 0 && CG(ini_parser_unbuffered_errors)) { - sprintf(error_buf, "%s in -d option on line 0\n", msg); + 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()); } diff --git a/sapi/cli/tests/gh20871.phpt b/sapi/cli/tests/gh20871.phpt index 4d5d7948ee9cd..99b825eaae851 100644 --- a/sapi/cli/tests/gh20871.phpt +++ b/sapi/cli/tests/gh20871.phpt @@ -18,12 +18,12 @@ print_r($output2); --EXPECTF-- Array ( - [0] => PHP: syntax error, unexpected '=' in -d option on line 0 + [0] => PHP: syntax error, unexpected '=' in INI command line parameter '-d' [1] => hello ) Array ( - [0] => PHP: syntax error, unexpected '!' in -d option on line 0 + [0] => PHP: syntax error, unexpected '!' in INI command line parameter '-d' [1] => world )