-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix GH-20286: use-after-destroy during userland stream_close(). #20348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: PHP-8.3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1077,6 +1077,14 @@ ZEND_API zend_result zend_call_method_if_exists( | |
| zend_object *object, zend_string *method_name, zval *retval, | ||
| uint32_t param_count, zval *params) | ||
| { | ||
| if (UNEXPECTED(!EG(active))) { | ||
| #if ZEND_DEBUG | ||
| ZEND_UNREACHABLE(); | ||
| #endif | ||
| ZVAL_UNDEF(retval); | ||
| return FAILURE; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should probably be a |
||
| } | ||
|
|
||
| zend_fcall_info fci; | ||
| fci.size = sizeof(zend_fcall_info); | ||
| fci.object = object; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --TEST-- | ||
| GH-20286 use after destroy on userland stream_close | ||
| --CREDITS-- | ||
| vi3tL0u1s | ||
| --SKIPIF-- | ||
| <?php | ||
| if (PHP_DEBUG) die('skip requires release build'); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| class lib { | ||
| public $context; | ||
| function stream_set() {} | ||
| function stream_set_option() {} | ||
| function stream_stat() { | ||
| return true; | ||
| } | ||
| function stream_open() { | ||
| return true; | ||
| } | ||
|
|
||
| function stream_read($count) { | ||
| function a() {} | ||
| include('lib://'); | ||
| } | ||
|
|
||
| function stream_close() { | ||
| include('lib://'); | ||
| } | ||
| } | ||
| stream_wrapper_register('lib', lib::class); | ||
| include('lib://test.php'); | ||
| ?> | ||
| --EXPECTF-- | ||
|
|
||
| Fatal error: Cannot redeclare a() (previously declared in %s:%d) in %s on line %d | ||
|
|
||
| Fatal error: Cannot redeclare a() (previously declared in %s:%d) in %s on line %d | ||
|
|
||
| Fatal error: Cannot redeclare a() (previously declared in %s:%d) in %s on line %d |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -695,6 +695,10 @@ static int php_userstreamop_close(php_stream *stream, int close_handle) | |
|
|
||
| assert(us != NULL); | ||
|
|
||
| if (UNEXPECTED(stream->wrapper->wops != &user_stream_wops)) { | ||
| stream->wrapper->wops = &user_stream_wops; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks a bit odd, why is this necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Program received signal SIGSEGV, Segmentation fault.
0x0000555555aa0f35 in _php_stream_free (stream=<optimized out>, close_options=close_options@entry=11) at /home/dcarlier/Contribs/php-src/main/streams/streams.c:505
505 stream->wrapper->wops->stream_closer(stream->wrapper, stream);
(gdb) p *stream->wrapper->wops
$2 = {stream_opener = 0x7ffff767be60, stream_closer = 0xc0d29af9ee47b9cc, stream_stat = 0xb, url_stat = 0x735f6d6165727473, dir_opener = 0x6f69747000746174,
label = 0x6e <error: Cannot access memory at address 0x6e>, unlink = 0x0, rename = 0x5555568bc500, stream_mkdir = 0x0, stream_rmdir = 0x5a0, stream_metadata = 0x7ffff767beb0}
(gdb) p *stream->wrapper->wops->stream_closer
Cannot access memory at address 0xc0d29af9ee47b9cc
(gdb) |
||
|
|
||
| ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1); | ||
|
|
||
| call_method_if_exists(&us->object, &func_name, &retval, 0, NULL); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.