Skip to content

Commit a7b6812

Browse files
committed
Fixed stream handler override
1 parent 0d48417 commit a7b6812

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

sapi/phpdbg/phpdbg.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ php_stream *phpdbg_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *
13561356
return stream;
13571357
}
13581358

1359-
return PHPDBG_G(orig_url_wrap_php)->stream_opener(wrapper, path, mode, options, opened_path, context STREAMS_CC);
1359+
return PHPDBG_G(orig_url_wrap_php)->wops->stream_opener(wrapper, path, mode, options, opened_path, context STREAMS_CC);
13601360
} /* }}} */
13611361

13621362
int main(int argc, char **argv) /* {{{ */
@@ -1399,6 +1399,7 @@ int main(int argc, char **argv) /* {{{ */
13991399
void* (*_malloc)(size_t);
14001400
void (*_free)(void*);
14011401
void* (*_realloc)(void*, size_t);
1402+
php_stream_wrapper wrapper;
14021403
php_stream_wrapper_ops wops;
14031404

14041405

@@ -1868,11 +1869,14 @@ int main(int argc, char **argv) /* {{{ */
18681869
}
18691870

18701871
{
1871-
php_stream_wrapper *wrapper = zend_hash_str_find_ptr(php_stream_get_url_stream_wrappers_hash(), ZEND_STRL("php"));
1872-
PHPDBG_G(orig_url_wrap_php) = wrapper->wops;
1873-
memcpy(&wops, wrapper->wops, sizeof(wops));
1872+
zval *zv = zend_hash_str_find(php_stream_get_url_stream_wrappers_hash(), ZEND_STRL("php"));
1873+
php_stream_wrapper *tmp_wrapper = Z_PTR_P(zv);
1874+
PHPDBG_G(orig_url_wrap_php) = tmp_wrapper;
1875+
memcpy(&wrapper, tmp_wrapper, sizeof(wrapper));
1876+
memcpy(&wops, tmp_wrapper->wops, sizeof(wops));
18741877
wops.stream_opener = phpdbg_stream_url_wrap_php;
1875-
wrapper->wops = &wops;
1878+
wrapper.wops = (const php_stream_wrapper_ops*)&wops;
1879+
Z_PTR_P(zv) = &wrapper;
18761880
}
18771881

18781882
/* Make stdin, stdout and stderr accessible from PHP scripts */
@@ -2151,8 +2155,8 @@ int main(int argc, char **argv) /* {{{ */
21512155
}
21522156

21532157
{
2154-
php_stream_wrapper *wrapper = zend_hash_str_find_ptr(php_stream_get_url_stream_wrappers_hash(), ZEND_STRL("php"));
2155-
wrapper->wops = PHPDBG_G(orig_url_wrap_php);
2158+
zval *zv = zend_hash_str_find(php_stream_get_url_stream_wrappers_hash(), ZEND_STRL("php"));
2159+
Z_PTR_P(zv) = (void*)PHPDBG_G(orig_url_wrap_php);
21562160
}
21572161

21582162
zend_hash_destroy(&PHPDBG_G(file_sources));

sapi/phpdbg/phpdbg.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
308308
zend_bool last_was_newline; /* check if we don't need to output a newline upon next phpdbg_error or phpdbg_notice */
309309

310310
FILE *stdin_file; /* FILE pointer to stdin source file */
311-
const php_stream_wrapper_ops *orig_url_wrap_php;
311+
const php_stream_wrapper *orig_url_wrap_php;
312312

313313
char input_buffer[PHPDBG_MAX_CMD]; /* stdin input buffer */
314314
int input_buflen; /* length of stdin input buffer */

0 commit comments

Comments
 (0)