Skip to content

Commit 85c4491

Browse files
sohomdatta1acmel
authored andcommitted
perf expr: Prevent normalize() from reading into undefined memory in the expression lexer
The current implementation does not account for a trailing backslash followed by a null-byte. If a null-byte is encountered following a backslash, normalize() will continue reading (and potentially writing) into garbage memory ignoring the EOS null-byte. Signed-off-by: Sohom Datta <[email protected]> Acked-by: Ian Rogers <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent c905ecf commit 85c4491

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/perf/util/expr.l

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ static char *normalize(char *str, int runtime)
4242
char *dst = str;
4343

4444
while (*str) {
45-
if (*str == '\\')
45+
if (*str == '\\') {
4646
*dst++ = *++str;
47+
if (!*str)
48+
break;
49+
}
4750
else if (*str == '?') {
4851
char *paramval;
4952
int i = 0;

0 commit comments

Comments
 (0)