Skip to content

Commit ea8a736

Browse files
committed
Fix GH-15179: Segmentation fault (null pointer dereference) in ext/standard/url_scanner_ex.re
Based on analysis by Ilija: #15179 (comment)
1 parent dc670cb commit ea8a736

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

ext/standard/url_scanner_ex.re

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ static inline int php_url_scanner_add_var_impl(const char *name, size_t name_len
736736
zend_string *encoded;
737737
url_adapt_state_ex_t *url_state;
738738
php_output_handler_func_t handler;
739+
bool should_start = false;
739740

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

748749
if (!url_state->active) {
749750
php_url_scanner_ex_activate(type);
750-
php_output_start_internal(ZEND_STRL("URL-Rewriter"), handler, 0, PHP_OUTPUT_HANDLER_STDFLAGS);
751+
should_start = true;
751752
url_state->active = 1;
752753
}
753754

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

790+
if (should_start) {
791+
php_output_start_internal(ZEND_STRL("URL-Rewriter"), handler, 0, PHP_OUTPUT_HANDLER_STDFLAGS);
792+
}
793+
789794
return SUCCESS;
790795
}
791796

tests/output/gh15179.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-15179 (Segmentation fault (null pointer dereference) in ext/standard/url_scanner_ex.re)
3+
--CREDITS--
4+
YuanchengJiang
5+
--INI--
6+
memory_limit=64M
7+
--SKIPIF--
8+
<?php
9+
if (getenv("USE_ZEND_ALLOC") === "0") die("skip requires ZendMM");
10+
?>
11+
--FILE--
12+
<?php
13+
$var = '';
14+
for ($i = 0; $i < 20; $i++) {
15+
$var .= str_repeat('a', 1 * 1024 * 1024);
16+
}
17+
18+
output_add_rewrite_var($var, $var);
19+
?>
20+
--EXPECTF--
21+
Fatal error: Allowed memory size of 67108864 bytes exhausted at %s

0 commit comments

Comments
 (0)