]> granicus.if.org Git - php/commitdiff
Don't assume that all includes have been executed
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 15 Feb 2019 16:36:40 +0000 (17:36 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 15 Feb 2019 16:36:40 +0000 (17:36 +0100)
ext/opcache/ZendAccelerator.c
ext/opcache/tests/preload_007.phpt [new file with mode: 0644]
ext/opcache/tests/preload_include.inc [new file with mode: 0644]
ext/opcache/tests/preload_include_dummy.inc [new file with mode: 0644]

index 3214477e63bf07d7be7ed3c01d72de131ea5059f..d03a8b3116de652db8976b9800cae67b5df2ee33 100644 (file)
@@ -3565,7 +3565,7 @@ static void preload_remove_empty_includes(void)
                                                if (resolved_path) {
                                                        zend_persistent_script *incl = zend_hash_find_ptr(preload_scripts, resolved_path);
                                                        zend_string_release(resolved_path);
-                                                       if (!incl->empty) {
+                                                       if (!incl || !incl->empty) {
                                                                empty = 0;
                                                                break;
                                                        }
@@ -3604,7 +3604,7 @@ static void preload_remove_empty_includes(void)
 
                                if (resolved_path) {
                                        zend_persistent_script *incl = zend_hash_find_ptr(preload_scripts, resolved_path);
-                                       if (incl->empty) {
+                                       if (incl && incl->empty) {
                                                MAKE_NOP(opline);
                                        } else {
                                                if (!IS_ABSOLUTE_PATH(Z_STRVAL_P(RT_CONSTANT(opline, opline->op1)), Z_STRLEN_P(RT_CONSTANT(opline, opline->op1)))) {
diff --git a/ext/opcache/tests/preload_007.phpt b/ext/opcache/tests/preload_007.phpt
new file mode 100644 (file)
index 0000000..2054cd8
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Handling of includes that were not executed
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.preload={PWD}/preload_include.inc
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+echo "Foobar";
+?>
+--EXPECTF--
+Foobar
diff --git a/ext/opcache/tests/preload_include.inc b/ext/opcache/tests/preload_include.inc
new file mode 100644 (file)
index 0000000..95369e7
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+
+$a = 1;
+$b = 2;
+if ($a == $b) {
+    include __DIR__ . "/preload_include_dummy.inc";
+}
diff --git a/ext/opcache/tests/preload_include_dummy.inc b/ext/opcache/tests/preload_include_dummy.inc
new file mode 100644 (file)
index 0000000..8fba097
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+
+echo "Dummy\n";