Skip to content

Commit fc1db70

Browse files
committed
Fix GH-16630: UAF in lexer with encoding translation and heredocs
zend_save_lexical_state() can be nested multiple times, for example for the parser initialization and then in the heredoc lexing. The input should not be freed if we restore to the same filtered string. Closes GH-16716.
1 parent cae2582 commit fc1db70

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PHP NEWS
1212
(frankenphp)). (nielsdos)
1313
. Fixed bug GH-16799 (Assertion failure at Zend/zend_vm_execute.h:7469).
1414
(nielsdos)
15+
. Fixed bug GH-16630 (UAF in lexer with encoding translation and heredocs).
16+
(nielsdos)
1517

1618
- FPM:
1719
. Fixed GH-16432 (PHP-FPM 8.2 SIGSEGV in fpm_get_status). (Jakub Zelenka)

Zend/tests/gh16630.phpt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-16630 (UAF in lexer with encoding translation and heredocs)
3+
--EXTENSIONS--
4+
mbstring
5+
--INI--
6+
zend.multibyte=On
7+
zend.script_encoding=ISO-8859-1
8+
internal_encoding=EUC-JP
9+
--FILE--
10+
<?php
11+
$data3 = <<<CODE
12+
heredoc
13+
text
14+
CODE;
15+
echo $data3;
16+
?>
17+
--EXPECT--
18+
heredoc
19+
text

Zend/zend_language_scanner.l

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ ZEND_API void zend_restore_lexical_state(zend_lex_state *lex_state)
275275
CG(zend_lineno) = lex_state->lineno;
276276
zend_restore_compiled_filename(lex_state->filename);
277277

278-
if (SCNG(script_filtered)) {
278+
if (SCNG(script_filtered) && SCNG(script_filtered) != lex_state->script_filtered) {
279279
efree(SCNG(script_filtered));
280280
SCNG(script_filtered) = NULL;
281281
}

0 commit comments

Comments
 (0)