Skip to content

Commit ccecdab

Browse files
committed
Fix phpGH-17831: zend_test_compile_string crash on nul bytes check.
happens with unset script name, using zend_str_val_nul_bytes instead thereafter.
1 parent a1da7ca commit ccecdab

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

ext/zend_test/test.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,16 @@ static ZEND_FUNCTION(zend_test_compile_string)
243243

244244
ZEND_PARSE_PARAMETERS_START(3, 3)
245245
Z_PARAM_STR(source_string)
246-
Z_PARAM_PATH_STR_EX(filename, 1, 0)
246+
Z_PARAM_PATH_STR(filename)
247247
Z_PARAM_LONG(position)
248248
ZEND_PARSE_PARAMETERS_END();
249249

250250
zend_op_array *op_array = NULL;
251251

252+
if (zend_str_has_nul_byte(filename)) {
253+
return;
254+
}
255+
252256
op_array = compile_string(source_string, ZSTR_VAL(filename), position);
253257

254258
if (op_array) {

ext/zend_test/tests/zend_test_compile_string.phpt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ try {
4949
echo $e->getMessage(), PHP_EOL;
5050
}
5151

52+
zend_test_compile_string($x, $y, $z);
5253

5354
$source_string = <<<EOF
5455
<?php
@@ -58,12 +59,24 @@ EOF;
5859
zend_test_compile_string($source_string, 'Source string', ZEND_COMPILE_POSITION_AFTER_OPEN_TAG);
5960

6061
?>
61-
--EXPECT--
62+
--EXPECTF--
6263
string(3) "php"
6364
#!/path/to/php
6465
string(3) "php"
6566
string(3) "php"
6667
string(3) "php"
6768
zend_test_compile_string(): Argument #2 ($filename) must not contain any null bytes
6869

70+
Warning: Undefined variable $x in %s on line %d
71+
72+
Warning: Undefined variable $y in %s on line %d
73+
74+
Warning: Undefined variable $z in %s on line %d
75+
76+
Deprecated: zend_test_compile_string(): Passing null to parameter #1 ($source_string) of type string is deprecated in %s on line %d
77+
78+
Deprecated: zend_test_compile_string(): Passing null to parameter #2 ($filename) of type string is deprecated in %s on line %d
79+
80+
Deprecated: zend_test_compile_string(): Passing null to parameter #3 ($position) of type int is deprecated in %s on line %d
81+
6982
Parse error: syntax error, unexpected token "<", expecting end of file in Source string on line 1

0 commit comments

Comments
 (0)