Merge branch 'PHP-7.4'

* PHP-7.4:
  Properly propagate url_stat exceptions during include
This commit is contained in:
Nikita Popov 2019-12-30 22:57:07 +01:00
commit d5c886ab7d
7 changed files with 60 additions and 10 deletions

View file

@ -11,14 +11,12 @@ set_error_handler(function($errno, $errstr, $errfile, $errline){
require 'notfound.php'; require 'notfound.php';
--EXPECTF-- --EXPECTF--
error(require(notfound.php): failed to open stream: %s) error(require(notfound.php): failed to open stream: %s)
Warning: Uncaught Exception: Foo in %sbug60909_1.php:5 Fatal error: Uncaught Exception: Foo in %sbug60909_1.php:5
Stack trace: Stack trace:
#0 %sbug60909_1.php(8): {closure}(2, 'require(notfoun...', '%s', 8) #0 %sbug60909_1.php(8): {closure}(2, 'require(notfoun...', '%s', 8)
#1 %sbug60909_1.php(8): require() #1 %sbug60909_1.php(8): require()
#2 {main} #2 {main}
thrown in %sbug60909_1.php on line 5 thrown in %sbug60909_1.php on line 5
Fatal error: main(): Failed opening required 'notfound.php' (include_path='%s') in %sbug60909_1.php on line 8
!!!shutdown!!! !!!shutdown!!!

View file

@ -0,0 +1,41 @@
--TEST--
Make sure exceptions during include/require stating are properly propagated
--FILE--
<?php
class StreamWrapper {
public function url_stat($path, $flags) {
throw new Exception('stat failed');
}
}
stream_wrapper_register('test', StreamWrapper::class);
set_include_path('test://foo:test://bar');
try {
require_once 'doesnt_exist.php';
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
require 'doesnt_exist.php';
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
include_once 'doesnt_exist.php';
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
include 'doesnt_exist.php';
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
stat failed
stat failed
stat failed
stat failed

View file

@ -4159,6 +4159,8 @@ static zend_never_inline zend_op_array* ZEND_FASTCALL zend_include_or_eval(zval
if (zend_hash_exists(&EG(included_files), resolved_path)) { if (zend_hash_exists(&EG(included_files), resolved_path)) {
goto already_compiled; goto already_compiled;
} }
} else if (UNEXPECTED(EG(exception))) {
break;
} else if (UNEXPECTED(strlen(Z_STRVAL_P(inc_filename)) != Z_STRLEN_P(inc_filename))) { } else if (UNEXPECTED(strlen(Z_STRVAL_P(inc_filename)) != Z_STRLEN_P(inc_filename))) {
zend_message_dispatcher( zend_message_dispatcher(
(type == ZEND_INCLUDE_ONCE) ? (type == ZEND_INCLUDE_ONCE) ?

View file

@ -637,11 +637,13 @@ ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type)
zend_save_lexical_state(&original_lex_state); zend_save_lexical_state(&original_lex_state);
if (open_file_for_scanning(file_handle)==FAILURE) { if (open_file_for_scanning(file_handle)==FAILURE) {
if (type==ZEND_REQUIRE) { if (!EG(exception)) {
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename); if (type==ZEND_REQUIRE) {
zend_bailout(); zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
} else { zend_bailout();
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename); } else {
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
}
} }
} else { } else {
op_array = zend_compile(ZEND_USER_FUNCTION); op_array = zend_compile(ZEND_USER_FUNCTION);

View file

@ -16,6 +16,4 @@ try {
Warning: main(): unable to create or locate filter "sample.filter" in %s on line %d Warning: main(): unable to create or locate filter "sample.filter" in %s on line %d
Warning: main(): Unable to create filter (sample.filter) in %s on line %d Warning: main(): Unable to create filter (sample.filter) in %s on line %d
Warning: main(): Failed opening '%s' for inclusion (include_path='%s') in %s on line %d
Undefined constant 'FOO' Undefined constant 'FOO'

View file

@ -559,6 +559,9 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) { if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) {
return zend_string_init(trypath, strlen(trypath), 0); return zend_string_init(trypath, strlen(trypath), 0);
} }
if (EG(exception)) {
return NULL;
}
} }
continue; continue;
} }
@ -596,6 +599,9 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) { if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) {
return zend_string_init(trypath, strlen(trypath), 0); return zend_string_init(trypath, strlen(trypath), 0);
} }
if (EG(exception)) {
return NULL;
}
} }
return NULL; return NULL;
} }

View file

@ -2067,6 +2067,9 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
options |= STREAM_ASSUME_REALPATH; options |= STREAM_ASSUME_REALPATH;
options &= ~USE_PATH; options &= ~USE_PATH;
} }
if (EG(exception)) {
return NULL;
}
} }
path_to_open = path; path_to_open = path;