mirror of
git://github.com/lxc/lxc
synced 2025-08-30 17:39:34 +00:00
caps: ensure \0-termination
Fixes: Coverity 1492865 Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
@@ -228,11 +228,11 @@ static int __caps_last_cap(__u32 *cap)
|
||||
if (fd >= 0) {
|
||||
ssize_t ret;
|
||||
unsigned int res;
|
||||
char buf[INTTYPE_TO_STRLEN(unsigned int)] = {0};
|
||||
char buf[INTTYPE_TO_STRLEN(unsigned int)];
|
||||
|
||||
ret = lxc_read_nointr(fd, buf, STRARRAYLEN(buf));
|
||||
if (ret <= 0)
|
||||
return syserror_set(EINVAL, "Failed to read \"/proc/sys/kernel/cap_last_cap\"");
|
||||
ret = lxc_read_string_nointr(fd, buf, STRARRAYLEN(buf));
|
||||
if (ret)
|
||||
return syserror("Failed to read \"/proc/sys/kernel/cap_last_cap\"");
|
||||
|
||||
ret = lxc_safe_uint(lxc_trim_whitespace_in_place(buf), &res);
|
||||
if (ret < 0)
|
||||
|
@@ -45,6 +45,22 @@ __hidden extern ssize_t lxc_send_nointr(int sockfd, void *buf, size_t len, int f
|
||||
|
||||
__hidden extern ssize_t lxc_read_nointr(int fd, void *buf, size_t count) __access_w(2, 3);
|
||||
|
||||
__access_w(2, 3) static inline int lxc_read_string_nointr(int fd, char *buf,
|
||||
size_t count)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
ret = lxc_read_nointr(fd, buf, STRARRAYLEN(buf));
|
||||
if (ret < 0)
|
||||
return -errno;
|
||||
if (ret == 0)
|
||||
return ret_errno(ENODATA);
|
||||
if ((size_t)ret >= sizeof(buf))
|
||||
return ret_errno(E2BIG);
|
||||
buf[ret] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
__hidden extern ssize_t lxc_read_nointr_expect(int fd, void *buf, size_t count,
|
||||
const void *expected_buf) __access_w(2, 3);
|
||||
|
||||
|
Reference in New Issue
Block a user