Skip to contentSkip to conversation

perf annotate: fix heap overflow

PATCH Applied Ian Rogers 4 participants 4 messages Oct 26, 2019 – Nov 12, 2019 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf annotate: fix heap overflow

Fix expand_tabs that copies the source lines '\0' and then appends another '\0' at a potentially out of bounds address.

---
 tools/perf/util/annotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/annotate.c +1 -1
index ef1866a902c4..bee0fee122f8 100644
@@ -1892,7 +1892,7 @@ static char *expand_tabs(char *line, char **storage, size_t *storage_len)
 	}
 
 	/* Expand the last region. */
-	len = line_len + 1 - src;
+	len = line_len - src;
 	memcpy(&new_line[dst], &line[src], len);
 	dst += len;
 	new_line[dst] = '\0';
Signature · 1 line
2.24.0.rc0.303.g954a862665-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Ian Rogers

Fix expand_tabs that copies the source lines '\0' and then appends another '\0' at a potentially out of bounds address.

not sure it could get out of bounds, but i think
the change is right, it matches the memcpy before
and I dont see reason to add +1

thanks,
jirka

Quoted 22 lines
---
 tools/perf/util/annotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/annotate.c +1 -1
index ef1866a902c4..bee0fee122f8 100644
@@ -1892,7 +1892,7 @@ static char *expand_tabs(char *line, char **storage, size_t *storage_len)
 	}
 
 	/* Expand the last region. */
-	len = line_len + 1 - src;
+	len = line_len - src;
 	memcpy(&new_line[dst], &line[src], len);
 	dst += len;
 	new_line[dst] = '\0';
Signature · 1 line
2.24.0.rc0.303.g954a862665-goog
#2 lore raw

Em Mon, Oct 28, 2019 at 08:29:08PM +0100, Jiri Olsa escreveu:

Quoted 9 lines · Ian Rogers
Quoted 2 lines

Fix expand_tabs that copies the source lines '\0' and then appends another '\0' at a potentially out of bounds address.

not sure it could get out of bounds, but i think
the change is right, it matches the memcpy before
and I dont see reason to add +1

Thanks, applied,

- Arnaldo

merge bot Applied
#3 lore raw

[tip: perf/core] perf annotate: Fix heap overflow

In reply to Ian Rogers
The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     5c65b1c0842f9daddc6aec4bdb4b5d898006be19
Gitweb:        https://git.kernel.org/tip/5c65b1c0842f9daddc6aec4bdb4b5d898006be19
Author:        Ian Rogers <[email protected]>
AuthorDate:    Fri, 25 Oct 2019 20:56:44 -07:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Thu, 07 Nov 2019 08:30:18 -03:00

perf annotate: Fix heap overflow

Fix expand_tabs that copies the source lines '\0' and then appends another '\0' at a potentially out of bounds address.

---
 tools/perf/util/annotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/annotate.c +1 -1
index ef1866a..bee0fee 100644
@@ -1892,7 +1892,7 @@ static char *expand_tabs(char *line, char **storage, size_t *storage_len)
 	}
 
 	/* Expand the last region. */
-	len = line_len + 1 - src;
+	len = line_len - src;
 	memcpy(&new_line[dst], &line[src], len);
 	dst += len;
 	new_line[dst] = '\0';