]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cmds: fix integer conversions
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 27 Sep 2021 10:04:34 +0000 (12:04 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 27 Sep 2021 10:07:51 +0000 (12:07 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cmd/lxc_user_nic.c
src/lxc/cmd/lxc_usernsexec.c

index 16ee4651d4ab81ad998a914ea56c0f893043e484..7d861f4afeba5899c9df2b70f85c67973b01ca3c 100644 (file)
@@ -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)
index a83444dad2c91665ecc9f8556568280b13eee937..9ac33e7414f95704c4f9be57f9fdf7833e8b5aa1 100644 (file)
@@ -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;
 }