Skip to content

Fix GH-15179: Segmentation fault (null pointer dereference) in ext/standard/url_scanner_ex.re #15206

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ext/standard/url_scanner_ex.re
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ static inline int php_url_scanner_add_var_impl(const char *name, size_t name_len
zend_string *encoded;
url_adapt_state_ex_t *url_state;
php_output_handler_func_t handler;
bool should_start = false;

if (type) {
url_state = &BG(url_adapt_session_ex);
Expand All @@ -747,7 +748,7 @@ static inline int php_url_scanner_add_var_impl(const char *name, size_t name_len

if (!url_state->active) {
php_url_scanner_ex_activate(type);
php_output_start_internal(ZEND_STRL("URL-Rewriter"), handler, 0, PHP_OUTPUT_HANDLER_STDFLAGS);
should_start = true;
url_state->active = 1;
}

Expand Down Expand Up @@ -786,6 +787,10 @@ static inline int php_url_scanner_add_var_impl(const char *name, size_t name_len
smart_str_free(&hname);
smart_str_free(&hvalue);

if (should_start) {
php_output_start_internal(ZEND_STRL("URL-Rewriter"), handler, 0, PHP_OUTPUT_HANDLER_STDFLAGS);
}

return SUCCESS;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/output/gh15179.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
GH-15179 (Segmentation fault (null pointer dereference) in ext/standard/url_scanner_ex.re)
--CREDITS--
YuanchengJiang
--INI--
memory_limit=64M
--SKIPIF--
<?php
if (getenv("USE_ZEND_ALLOC") === "0") die("skip requires ZendMM");
?>
--FILE--
<?php
$var = str_repeat('a', 20 * 1024 * 1024);

output_add_rewrite_var($var, $var);
?>
--EXPECTF--
Fatal error: Allowed memory size of %d bytes exhausted %s
Loading