From fd20fac619d6ecc995ee35f077236643a6d1f22d Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 16 Feb 2025 10:36:32 +0000 Subject: [PATCH 1/2] Fix GH-17831: zend_test_compile_string crash on nul bytes check. happens with unset script path, now using zend_str_has_nul_bytes thereafter. --- ext/zend_test/test.c | 6 +++++- ext/zend_test/tests/zend_test_compile_string.phpt | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index 1d4c14dd07e3f..3cb498fa20d33 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -243,12 +243,16 @@ static ZEND_FUNCTION(zend_test_compile_string) ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_STR(source_string) - Z_PARAM_PATH_STR_EX(filename, 1, 0) + Z_PARAM_PATH_STR(filename) Z_PARAM_LONG(position) ZEND_PARSE_PARAMETERS_END(); zend_op_array *op_array = NULL; + if (zend_str_has_nul_byte(filename)) { + return; + } + op_array = compile_string(source_string, ZSTR_VAL(filename), position); if (op_array) { diff --git a/ext/zend_test/tests/zend_test_compile_string.phpt b/ext/zend_test/tests/zend_test_compile_string.phpt index c03c46b0100dc..c46b2b671937e 100644 --- a/ext/zend_test/tests/zend_test_compile_string.phpt +++ b/ext/zend_test/tests/zend_test_compile_string.phpt @@ -49,6 +49,7 @@ try { echo $e->getMessage(), PHP_EOL; } +zend_test_compile_string($x, $y, $z); $source_string = << ---EXPECT-- +--EXPECTF-- string(3) "php" #!/path/to/php string(3) "php" @@ -66,4 +67,16 @@ string(3) "php" string(3) "php" zend_test_compile_string(): Argument #2 ($filename) must not contain any null bytes +Warning: Undefined variable $x in %s on line %d + +Warning: Undefined variable $y in %s on line %d + +Warning: Undefined variable $z in %s on line %d + +Deprecated: zend_test_compile_string(): Passing null to parameter #1 ($source_string) of type string is deprecated in %s on line %d + +Deprecated: zend_test_compile_string(): Passing null to parameter #2 ($filename) of type string is deprecated in %s on line %d + +Deprecated: zend_test_compile_string(): Passing null to parameter #3 ($position) of type int is deprecated in %s on line %d + Parse error: syntax error, unexpected token "<", expecting end of file in Source string on line 1 From 5f6ca03fc8f52bf0d3df1ba1d5de94126d9ff9d5 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 16 Feb 2025 10:48:36 +0000 Subject: [PATCH 2/2] changes from review --- ext/zend_test/test.c | 4 ---- ext/zend_test/tests/zend_test_compile_string.phpt | 8 +------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index 3cb498fa20d33..3ec469382cad9 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -249,10 +249,6 @@ static ZEND_FUNCTION(zend_test_compile_string) zend_op_array *op_array = NULL; - if (zend_str_has_nul_byte(filename)) { - return; - } - op_array = compile_string(source_string, ZSTR_VAL(filename), position); if (op_array) { diff --git a/ext/zend_test/tests/zend_test_compile_string.phpt b/ext/zend_test/tests/zend_test_compile_string.phpt index c46b2b671937e..fb47f748f87a7 100644 --- a/ext/zend_test/tests/zend_test_compile_string.phpt +++ b/ext/zend_test/tests/zend_test_compile_string.phpt @@ -49,7 +49,7 @@ try { echo $e->getMessage(), PHP_EOL; } -zend_test_compile_string($x, $y, $z); +zend_test_compile_string(null, null, null); $source_string = <<