diff options
author | Steven Rostedt (Google) <rostedt@goodmis.org> | 2022-12-19 22:26:30 -0500 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2023-01-03 16:39:09 -0500 |
commit | 8be5640ff4e64ca07b9c711afc0af89c958ed4f2 (patch) | |
tree | 5614f5507143a5094247573532dd5f29b7d7c9d0 | |
parent | d227f133a84c1b67643857bee1badadd0f3d5846 (diff) | |
download | libtraceevent-8be5640ff4e64ca07b9c711afc0af89c958ed4f2.tar.gz |
libtraceevent: Fix string parsing
The string parsing of tokens can be confused if the string has a backslash
at the end of the string. That is "\\\0" or \<nul>. The backslash will
skip the next character. If the next character is the end of the string,
it will read past the end of the string.
Check for end of buffer (less than or equal to 0), and if the next
character is the end of buffer, exit the loop regardless if the previous
character was a backslash.
Also fail the parsing of the event if the string is not terminated by the
quote that started it.
Link: https://lore.kernel.org/linux-trace-devel/20221219222630.54fc5bc5@gandalf.local.home
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r-- | src/event-parse.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/event-parse.c b/src/event-parse.c index b37d81a..8167777 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -1303,10 +1303,15 @@ static enum tep_event_type __read_token(struct tep_handle *tep, char **tok) if (ch == '\\' && last_ch == '\\') last_ch = 0; /* Break out if the file is corrupted and giving non print chars */ + if (ch <= 0) + break; } while ((ch != quote_ch && isprint(ch)) || last_ch == '\\' || ch == '\n'); /* remove the last quote */ i--; + if (ch <= 0) + type = TEP_EVENT_NONE; + /* * For strings (double quotes) check the next token. * If it is another string, concatinate the two. |