pass: Fix the not-null terminated string 44/152544/4
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 26 Sep 2017 09:54:59 +0000 (18:54 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 27 Sep 2017 01:11:41 +0000 (10:11 +0900)
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 <cw00.choi@samsung.com>
src/core/common.c

index 333c873..b75a016 100644 (file)
@@ -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)