]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: fix integer comparisons
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 3 Sep 2021 08:14:44 +0000 (10:14 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 3 Sep 2021 11:01:01 +0000 (13:01 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index be9d3072b09987ce2bf96c5548000f7afe49f508..1c3cfc3b30cedb35e17b1b48dbf18415fb0654f5 100644 (file)
@@ -2803,7 +2803,7 @@ FILE *make_anonymous_mount_file(const struct list_head *mount_entries,
                len = strlen(entry->val);
 
                ret = lxc_write_nointr(fd, entry->val, len);
-               if (ret != len)
+               if (ret < 0 || (size_t)ret != len)
                        return NULL;
 
                ret = lxc_write_nointr(fd, "\n", 1);
@@ -3438,7 +3438,7 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
                return log_error_errno(-1, errno, "Failed to open \"%s\"", path);
 
        ret = lxc_write_nointr(fd, buf, buf_size);
-       if (ret != buf_size)
+       if (ret < 0 || (size_t)ret != buf_size)
                return log_error_errno(-1, errno, "Failed to write %cid mapping to \"%s\"",
                                       idtype == ID_TYPE_UID ? 'u' : 'g', path);
 
@@ -3509,7 +3509,9 @@ static struct id_map *find_mapped_hostid_entry(const struct list_head *idmap,
 
 int lxc_map_ids(struct list_head *idmap, pid_t pid)
 {
-       int hostuid, hostgid, fill, left;
+       int fill, left;
+       uid_t hostuid;
+       gid_t hostgid;
        char u_or_g;
        char *pos;
        char cmd_output[PATH_MAX];
@@ -3718,7 +3720,7 @@ static int lxc_transient_proc(struct lxc_rootfs *rootfs)
                        return log_error_errno(-errno, errno, "Failed to create %d(proc)", rootfs->dfd_mnt);
 
                goto domount;
-       } else if (link_len >= sizeof(link)) {
+       } else if ((size_t)link_len >= sizeof(link)) {
                return log_error_errno(-EIO, EIO, "Truncated link target");
        }
        link[link_len] = '\0';
@@ -4116,14 +4118,14 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
        if (!info_new->tty)
                return ret_errno(ENOMEM);
 
-       for (int i = 0; i < ttys_max; i++) {
+       for (size_t i = 0; i < ttys_max; i++) {
                terminal_info = &info_new->tty[i];
                terminal_info->busy = -1;
                terminal_info->ptx = -EBADF;
                terminal_info->pty = -EBADF;
        }
 
-       for (int i = 0; i < ttys_max; i++) {
+       for (size_t i = 0; i < ttys_max; i++) {
                int ptx = -EBADF, pty = -EBADF;
 
                ret = lxc_abstract_unix_recv_two_fds(sock, &ptx, &pty);
@@ -5521,11 +5523,11 @@ static char *getuname(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 = zalloc(bufsize);
@@ -5549,11 +5551,11 @@ static char *getgname(void)
        __do_free char *buf = NULL;
        struct group grent;
        struct group *grentp = NULL;
-       size_t bufsize;
+       ssize_t bufsize;
        int ret;
 
        bufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
-       if (bufsize == -1)
+       if (bufsize < 0)
                bufsize = 1024;
 
        buf = zalloc(bufsize);