From: Christian Brauner Date: Mon, 27 Sep 2021 10:04:34 +0000 (+0200) Subject: cmds: fix integer conversions X-Git-Tag: lxc-5.0.0~85^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98775a4cc98f03d67e87b07cc9603a2ac4b6d9bb;p=thirdparty%2Flxc.git cmds: fix integer conversions Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c index 16ee4651d..7d861f4af 100644 --- a/src/lxc/cmd/lxc_user_nic.c +++ b/src/lxc/cmd/lxc_user_nic.c @@ -111,11 +111,11 @@ static char *get_username(void) __do_free char *buf = NULL; struct passwd pwent; struct passwd *pwentp = NULL; - size_t bufsize; + ssize_t bufsize; int ret; bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); - if (bufsize == -1) + if (bufsize < 0) bufsize = 1024; buf = malloc(bufsize); @@ -144,7 +144,7 @@ static char **get_groupnames(void) int ret, i; struct group grent; struct group *grentp = NULL; - size_t bufsize; + ssize_t bufsize; ngroups = getgroups(0, NULL); if (ngroups < 0) { @@ -174,7 +174,7 @@ static char **get_groupnames(void) } bufsize = sysconf(_SC_GETGR_R_SIZE_MAX); - if (bufsize == -1) + if (bufsize < 0) bufsize = 1024; buf = malloc(bufsize); @@ -659,6 +659,7 @@ static char *get_nic_if_avail(int fd, struct alloted_s *names, int pid, size_t length = 0; int ret; size_t slen; + ssize_t nbytes; char *owner; char nicname[IFNAMSIZ]; struct alloted_s *n; @@ -755,7 +756,8 @@ static char *get_nic_if_avail(int fd, struct alloted_s *names, int pid, return NULL; } - if (lxc_pwrite_nointr(fd, newline, slen, length) != slen) { + nbytes = lxc_pwrite_nointr(fd, newline, slen, length); + if (nbytes < 0 || (size_t)nbytes != slen) { CMD_SYSERROR("Failed to append new entry \"%s\" to database file", newline); if (lxc_netdev_delete_by_name(nicname) != 0) diff --git a/src/lxc/cmd/lxc_usernsexec.c b/src/lxc/cmd/lxc_usernsexec.c index a83444dad..9ac33e741 100644 --- a/src/lxc/cmd/lxc_usernsexec.c +++ b/src/lxc/cmd/lxc_usernsexec.c @@ -228,13 +228,13 @@ static int read_default_map(char *fnam, int which, char *user) static int find_default_map(void) { __do_free char *buf = NULL; - size_t bufsize; + ssize_t bufsize; struct passwd pwent; int ret = -1; struct passwd *pwentp = NULL; bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); - if (bufsize == -1) + if (bufsize < 0) bufsize = 1024; buf = malloc(bufsize); @@ -261,12 +261,14 @@ static int find_default_map(void) return 0; } -static bool is_in_ns_range(long id, struct id_map *map) +static bool is_in_ns_range(unsigned long id, struct id_map *map) { if (id < map->nsid) return false; + if (id >= map->nsid + map->range) return false; + return true; }