Skip to content

Fix #76813: Access_violation_near_NULL_on_source_operand #6464

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion sapi/phpdbg/phpdbg_lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ ADDR [0][x][a-fA-F0-9]+
OPCODE (ZEND_|zend_)([A-Za-z])+
INPUT ("\\"[#"']|["]("\\\\"|"\\"["]|[^\n\000"])+["]|[']("\\"[']|"\\\\"|[^\n\000'])+[']|[^\n\000#"'])+

<!*> := yyleng = (size_t) YYCURSOR - (size_t) yytext;
<!*> {
if (YYCURSOR == NULL) return T_UNEXPECTED;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does YYCURSOR become null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condider the following input: "a\b". When backtracking, re2c sets YYCURSOR to YYMARKER, which is NULL. The re2c documentation says it would not be necessary to initialize YYMARKER, but when I do it nonetheless, there is no NULL issue here anymore, but for some reason the lexer enters the <NORMAL>{GENERIC_ID} rule, albeit with an empty text (yyleng == 0) what causes issues in unescape_string(). I don't understand why that rule is executed, since GENERIC_ID is not supposed to be empty. Anyway, if I add a suitable default rule <NORMAL>* {return T_UNEXPECTED;}, I get the desired parse error.

yyleng = (size_t) YYCURSOR - (size_t) yytext;
}

<*>[\n\000] {
return 0;
Expand Down
8 changes: 6 additions & 2 deletions sapi/phpdbg/phpdbg_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ typedef void* yyscan_t;
%% /* Rules */

input
: command { $$ = $1; }
| input T_SEPARATOR command { phpdbg_stack_separate($1.top); $$ = $3; }
: non_empty_input { $$ = $1; }
| /* empty */
;

non_empty_input
: command { $$ = $1; }
| non_empty_input T_SEPARATOR command { phpdbg_stack_separate($1.top); $$ = $3; }
;

command
: parameters { $$.top = PHPDBG_G(parser_stack)->top; }
| full_expression { phpdbg_stack_push(PHPDBG_G(parser_stack), &$1); $$.top = PHPDBG_G(parser_stack)->top; }
Expand Down
10 changes: 10 additions & 0 deletions sapi/phpdbg/tests/bug76813.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Bug #76813 (Access_violation_near_NULL_on_source_operand)
--PHPDBG--
"#!==)===\377\377\276\242="
#!==)===\377\377\276\242=
--EXPECT--
prompt> [Parse Error: syntax error, unexpected input, expecting $end]
prompt> [Parse Error: syntax error, unexpected # (pound sign), expecting $end]
prompt> [Parse Error: syntax error, unexpected # (pound sign), expecting $end]
prompt>