Skip to content

Commit 527ce26

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix phpGH-19792: SCCP causes UAF for return value if both warning and exception are triggered
2 parents 05eda43 + 3026e88 commit 527ce26

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

Zend/Optimizer/sccp.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,7 @@ static inline zend_result ct_eval_func_call_ex(
838838
zval_ptr_dtor(result);
839839
zend_clear_exception();
840840
retval = FAILURE;
841-
}
842-
843-
if (EG(capture_warnings_during_sccp) > 1) {
841+
} else if (EG(capture_warnings_during_sccp) > 1) {
844842
zval_ptr_dtor(result);
845843
retval = FAILURE;
846844
}

ext/opcache/tests/opt/gh19792.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-19792 (SCCP causes UAF for return value if both warning and exception are triggered)
3+
--EXTENSIONS--
4+
opcache
5+
zend_test
6+
--INI--
7+
opcache.enable=1
8+
opcache.enable_cli=1
9+
opcache.optimization_level=-1
10+
--FILE--
11+
<?php
12+
13+
function foo()
14+
{
15+
return \zend_test_gh19792();
16+
}
17+
18+
try {
19+
foo();
20+
} catch (Error $e) {
21+
echo $e->getMessage(), "\n";
22+
}
23+
24+
?>
25+
--EXPECTF--
26+
Warning: a warning in %s on line %d
27+
an exception

ext/zend_test/test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,3 +1731,12 @@ static PHP_FUNCTION(zend_test_opcache_preloading)
17311731

17321732
RETURN_BOOL(opcache_preloading());
17331733
}
1734+
1735+
static PHP_FUNCTION(zend_test_gh19792)
1736+
{
1737+
ZEND_PARSE_PARAMETERS_NONE();
1738+
1739+
RETVAL_STRING("this is a non-interned string");
1740+
zend_error(E_WARNING, "a warning");
1741+
zend_throw_error(NULL, "an exception");
1742+
}

ext/zend_test/test.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ function zend_test_gh18756(): void {}
344344
function zend_test_opcache_preloading(): bool {}
345345

346346
function zend_test_uri_parser(string $uri, string $parser): array { }
347+
348+
/** @compile-time-eval */
349+
function zend_test_gh19792(): void {}
347350
}
348351

349352
namespace ZendTestNS {

ext/zend_test/test_arginfo.h

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)