perf tests: Do not assume that readlink() returns a null terminated string
authorTommi Rantala <tommi.t.rantala@nokia.com>
Wed, 22 Mar 2017 13:06:21 +0000 (15:06 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 27 Mar 2017 18:35:56 +0000 (15:35 -0300)
Ensure that the string in buf is null terminated.

Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20170322130624.21881-4-tommi.t.rantala@nokia.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/sdt.c

index f59d210e1bafbe21f5689587b718a8fb04f252cc..26e5b7a0b839d1b87611201ecf3bf7ede912c5ed 100644 (file)
@@ -43,7 +43,7 @@ static char *get_self_path(void)
 {
        char *buf = calloc(PATH_MAX, sizeof(char));
 
-       if (buf && readlink("/proc/self/exe", buf, PATH_MAX) < 0) {
+       if (buf && readlink("/proc/self/exe", buf, PATH_MAX - 1) < 0) {
                pr_debug("Failed to get correct path of perf\n");
                free(buf);
                return NULL;