]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
caps: fix illegal access to array bound
author2xsec <dh48.jeong@samsung.com>
Mon, 3 Sep 2018 06:10:05 +0000 (15:10 +0900)
committer2xsec <dh48.jeong@samsung.com>
Mon, 3 Sep 2018 06:10:35 +0000 (15:10 +0900)
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
src/lxc/caps.c

index 8ca47bf66c00e906b85790fd96e89335ae5e9feb..9197b1345444d40d54e3ba9276871e364343ca60 100644 (file)
@@ -296,15 +296,13 @@ static long int _real_caps_last_cap(void)
        if (fd >= 0) {
                ssize_t n;
                char *ptr;
-               char buf[INTTYPE_TO_STRLEN(int)];
+               char buf[INTTYPE_TO_STRLEN(int)] = {0};
 
        again:
-               n = read(fd, buf, sizeof(buf));
+               n = read(fd, buf, sizeof(buf) - 1);
                if (n < 0 && errno == EINTR) {
                        goto again;
                } else if (n >= 0) {
-                       buf[n] = '\0';
-
                        errno = 0;
                        result = strtol(buf, &ptr, 10);
                        if (!ptr || (*ptr != '\0' && *ptr != '\n') || errno != 0)