From: 2xsec Date: Mon, 3 Sep 2018 06:10:05 +0000 (+0900) Subject: caps: fix illegal access to array bound X-Git-Tag: lxc-3.1.0~119^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22b67bfa969b2d7f6f3f757e7401b1cc47302725;p=thirdparty%2Flxc.git caps: fix illegal access to array bound Signed-off-by: 2xsec --- 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)