Skip to content

Commit

Permalink
fix parsing crash
Browse files Browse the repository at this point in the history
  • Loading branch information
bottiger1 committed Jun 5, 2024
1 parent 1bcc5b8 commit 48f55de
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/logic/TextParsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
SMCResult res;
SMCStates states;
char c;
bool end_of_last_buffer_was_backslash = false;

StringInfo strings[3];
StringInfo emptystring;
Expand Down Expand Up @@ -383,6 +384,10 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (reparse_point)
{
read += (parse_point - reparse_point);
if(read > 0)
{
end_of_last_buffer_was_backslash = reparse_point[-1] == '\\';
}
parse_point = reparse_point;
reparse_point = NULL;
}
Expand Down Expand Up @@ -454,7 +459,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (in_quote)
{
/* If i was 0, we could have reparsed, so make sure there's no buffer underrun */
if ((&parse_point[i] != in_buf) && c == '"' && parse_point[i-1] != '\\')
if ( (&parse_point[i] != in_buf) && c == '"' && !((i == 0 && end_of_last_buffer_was_backslash) || (i > 0 && parse_point[i-1] == '\\')) )
{
/* If we reached a quote in an ignore phase,
* we're staging a string and we must rotate it out.
Expand Down Expand Up @@ -726,6 +731,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (parse_point)
{
parse_point = &parse_point[read];
end_of_last_buffer_was_backslash = parse_point[-1] == '\\';
parse_point -= bytes;
}
}
Expand Down

0 comments on commit 48f55de

Please sign in to comment.