Skip to content

Commit 2e564a7

Browse files
committed
Fix GH-17387: crash on unterminated quote in phpdbg lexer
In the NORMAL condition a lone unterminated quote matched no rule, so re2c backtracked to a zero-length GENERIC_ID accept. The rule body then computed yyleng - unescape_string(yytext) as 0 - N, underflowing size_t into a multi-gigabyte estrndup. Give a bare quote an explicit one-character accept so the cursor advances and unescape_string is never reached with a malformed token. Fixes GH-17387 Closes GH-22506
1 parent efbf473 commit 2e564a7

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ PHP NEWS
1515
copying, ArrayAccess, stream lookup, directory iteration and extraction.
1616
(Weilin Du)
1717

18+
- PHPDBG:
19+
. Fixed bug GH-17387 (Trivial crash in phpdbg lexer). (iliaal)
20+
1821
- Reflection:
1922
. Fixed bug GH-22324 (Ignore leading namespace separator in
2023
ReflectionParameter::__construct()). (jorgsowa)

‎sapi/phpdbg/phpdbg_lexer.l‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ INPUT ("\\"[#"']|["]("\\\\"|"\\"["]|[^\n\000"])*["]|[']("\\"[']|"\\\\"|[^\
166166
return T_ID;
167167
}
168168
169+
<NORMAL>["'] {
170+
phpdbg_init_param(yylval, STR_PARAM);
171+
yylval->str = estrndup(yytext, yyleng);
172+
yylval->len = yyleng;
173+
return T_ID;
174+
}
175+
169176
<RAW>{INPUT} {
170177
phpdbg_init_param(yylval, STR_PARAM);
171178
yylval->str = estrdup(yytext);

‎sapi/phpdbg/tests/gh17387.phpt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
GH-17387 (Trivial crash in phpdbg lexer)
3+
--PHPDBG--
4+
a';
5+
q
6+
--EXPECT--
7+
prompt> [The command "a" could not be found]
8+
prompt>

0 commit comments

Comments
 (0)