perf tools: Fix handling read result using a signed variable
authorAndrzej Hajda <a.hajda@samsung.com>
Tue, 6 Oct 2015 09:00:17 +0000 (11:00 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 6 Oct 2015 21:04:59 +0000 (18:04 -0300)
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

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: kernel-janitors@vger.kernel.org
Link: http://lkml.kernel.org/r/1444122017-16856-1-git-send-email-a.hajda@samsung.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/event.c

index cb98b5af9e1757f842da2c51c6a92348d8d7fd28..8b10621b415c684564a6dd5af130ebc9d3ab33c7 100644 (file)
@@ -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;