Skip to contentSkip to conversation

perf tools: fix handling read result

PATCH Applied Andrzej Hajda 3 participants 3 messages Oct 6, 2015 – Oct 8, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tools: fix handling read result

The function can return negative value, assigning it to unsigned variable can cause memory corruption.

The problem has been detected using proposed semantic patch scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

---
 tools/perf/util/event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/event.c +2 -1
index cb98b5a..8b10621 100644
@@ -67,7 +67,8 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
 	char filename[PATH_MAX];
 	char bf[4096];
 	int fd;
-	size_t size = 0, n;
+	size_t size = 0;
+	ssize_t n;
 	char *nl, *name, *tgids, *ppids;
 
 	*tgid = -1;
Signature · 1 line
1.9.1
maintainer Applied
#1 lore raw

Em Tue, Oct 06, 2015 at 11:00:17AM +0200, Andrzej Hajda escreveu:

Quoted 7 lines

The function can return negative value, assigning it to unsigned variable can cause memory corruption.

The problem has been detected using proposed semantic patch scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

Thanks, applied.

- Arnaldo

#2 lore raw

[tip:perf/core] perf tools: Fix handling read result using a signed variable

In reply to Andrzej Hajda
perf tools: Fix handling read result using a signed variable
Commit-ID:  38349665388fb079fb2bc8c46db9446dd976802a
Gitweb:     http://git.kernel.org/tip/38349665388fb079fb2bc8c46db9446dd976802a
Author:     Andrzej Hajda <[email protected]>
AuthorDate: Tue, 6 Oct 2015 11:00:17 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 6 Oct 2015 18:04:59 -0300

perf tools: Fix handling read result using a signed variable

The function can return negative value, assigning it to unsigned variable can cause memory corruption.

The problem has been detected using proposed semantic patch scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

---
 tools/perf/util/event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/event.c +2 -1
index cb98b5a..8b10621 100644
@@ -67,7 +67,8 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
 	char filename[PATH_MAX];
 	char bf[4096];
 	int fd;
-	size_t size = 0, n;
+	size_t size = 0;
+	ssize_t n;
 	char *nl, *name, *tgids, *ppids;
 
 	*tgid = -1;