From 6c7aea41255d08c711052678789ca93ca5b98a1d Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 26 Sep 2017 18:54:59 +0900 Subject: [PATCH] pass: Fix the not-null terminated string The read() function doesn't add the '\0' character to the end of string. So, this patch adds the '\0' char on the last point of string if there is no error. Change-Id: I1b3bf879b9c38f19edad8279d036c68655fae83b Signed-off-by: Chanwoo Choi --- src/core/common.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/common.c b/src/core/common.c index 333c873..b75a016 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -58,8 +58,12 @@ int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) ret = read(fd, buf, PATH_MAX); close(fd); - if (ret < 0) + if ((ret >= 0) && (ret <= PATH_MAX)) { + buf[ret] = '\0'; + } else { + errno = EIO; return -1; + } filename = strrchr(buf, '/'); if (filename == NULL) -- 2.7.4