Skip to content

Commit

Permalink
coverity: #1425760
Browse files Browse the repository at this point in the history
Use of untrusted scalar value

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Jun 15, 2018
1 parent f4ea735 commit 2246ba1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lxc/tools/lxc_ls.c
Expand Up @@ -1136,17 +1136,27 @@ static int ls_serialize(int wpipefd, struct ls *n)

static int ls_recv_str(int fd, char **buf)
{
ssize_t ret;
size_t slen = 0;
if (lxc_read_nointr(fd, &slen, sizeof(slen)) != sizeof(slen))

ret = lxc_read_nointr(fd, &slen, sizeof(slen));
if (ret != sizeof(slen))
return -1;

if (slen > 0) {
*buf = malloc(sizeof(char) * (slen + 1));
if (!*buf)
return -1;
if (lxc_read_nointr(fd, *buf, slen) != (ssize_t)slen)

ret = lxc_read_nointr(fd, *buf, slen);
if (ret != (ssize_t)slen) {
free(*buf);
return -1;
}

(*buf)[slen] = '\0';
}

return 0;
}

Expand Down

0 comments on commit 2246ba1

Please sign in to comment.