Skip to content

Commit cefdf00

Browse files
committed
Fix GH-17899: zend_test_compile_string crash on invalid script path.
when opcache is enabled. close GH-17901
1 parent 769f292 commit cefdf00

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ PHP NEWS
4242
. Fixed bug GH-17654 (Multiple classes using same trait causes function
4343
JIT crash). (nielsdos)
4444
. Fixed bug GH-17577 (JIT packed type guard crash). (nielsdos, Dmitry)
45+
. Fixed bug GH-17899 (zend_test_compile_string with invalid path
46+
when opcache is enabled). (David Carlier)
4547

4648
- PDO_SQLite:
4749
. Fixed GH-17837 ()::getColumnMeta() on unexecuted statement segfaults).

ext/opcache/ZendAccelerator.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,12 @@ zend_string *accel_make_persistent_key(zend_string *str)
13341334
EXPECTED((parent_script = zend_get_executed_filename_ex()) != NULL)) {
13351335

13361336
parent_script_len = ZSTR_LEN(parent_script);
1337-
while ((--parent_script_len > 0) && !IS_SLASH(ZSTR_VAL(parent_script)[parent_script_len]));
1337+
while (parent_script_len > 0) {
1338+
--parent_script_len;
1339+
if (IS_SLASH(ZSTR_VAL(parent_script)[parent_script_len])) {
1340+
break;
1341+
}
1342+
}
13381343

13391344
if (UNEXPECTED((size_t)(key_length + parent_script_len + 1) >= ZCG_KEY_LEN)) {
13401345
return NULL;

ext/zend_test/tests/gh17899.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
GH-17899 (zend_test_compile_string with opcache crash on invalid script path)
3+
--EXTENSIONS--
4+
zend_test
5+
--INI--
6+
opcache.enable_cli=1
7+
--CREDITS--
8+
YuanchengJiang
9+
--FILE--
10+
<?php
11+
$source = '<?php
12+
require("sumfile.php");
13+
?>';
14+
try {zend_test_compile_string($source,$source,$c);} catch (Exception $e) { echo($e); }
15+
--EXPECTF--
16+
17+
Warning: Undefined variable $c in %s on line %d
18+
19+
Deprecated: zend_test_compile_string(): Passing null to parameter #3 ($position) of type int is deprecated in %s on line %d
20+
21+
Warning: require(sumfile.php): Failed to open stream: No such file or directory in <?php
22+
require("sumfile.php");
23+
?> on line %d
24+
25+
Fatal error: Uncaught Error: Failed opening required 'sumfile.php' (include_path='.%s') in <?php
26+
require("sumfile.php");
27+
?>:%d
28+
Stack trace:
29+
#0 %s(%d): zend_test_compile_string('<?php\nrequire("...', '<?php\nrequire("...', NULL)
30+
#1 {main}
31+
thrown in <?php
32+
require("sumfile.php");
33+
?> on line %d
34+

0 commit comments

Comments
 (0)