From 22b67bfa969b2d7f6f3f757e7401b1cc47302725 Mon Sep 17 00:00:00 2001 From: 2xsec Date: Mon, 3 Sep 2018 15:10:05 +0900 Subject: [PATCH] caps: fix illegal access to array bound Signed-off-by: 2xsec --- src/lxc/caps.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lxc/caps.c b/src/lxc/caps.c index 8ca47bf66..9197b1345 100644 --- a/src/lxc/caps.c +++ b/src/lxc/caps.c @@ -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) -- 2.47.2