[PATCH 18/20] perf utils: use sizeof(buf) - 1 in readlink() call

From: Arnaldo Carvalho de Melo
Date: Mon Mar 27 2017 - 21:40:20 EST


From: Tommi Rantala <tommi.t.rantala@xxxxxxxxx>

Ensure that we have space for the null byte in buf.

Signed-off-by: Tommi Rantala <tommi.t.rantala@xxxxxxxxx>
Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Link: http://lkml.kernel.org/r/20170322130624.21881-5-tommi.t.rantala@xxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/header.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 05714d548584..cf22962ce725 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -378,7 +378,7 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused,
* actual atual path to perf binary
*/
sprintf(proc, "/proc/%d/exe", getpid());
- ret = readlink(proc, buf, sizeof(buf));
+ ret = readlink(proc, buf, sizeof(buf) - 1);
if (ret <= 0)
return -1;

--
2.9.3