From: Tommi Rantala Date: Wed, 22 Mar 2017 13:06:21 +0000 (+0200) Subject: perf tests: Do not assume that readlink() returns a null terminated string X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0e6ba11511aef91ba8e2528ddc681d88922d7b0b;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git perf tests: Do not assume that readlink() returns a null terminated string Ensure that the string in buf is null terminated. Signed-off-by: Tommi Rantala Cc: Alexander Shishkin Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20170322130624.21881-4-tommi.t.rantala@nokia.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/tests/sdt.c b/tools/perf/tests/sdt.c index f59d210e1baf..26e5b7a0b839 100644 --- a/tools/perf/tests/sdt.c +++ b/tools/perf/tests/sdt.c @@ -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;