]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
unshare: make sure map_range.next is initialized [coverity scan]
authorKarel Zak <kzak@redhat.com>
Thu, 7 Dec 2023 12:54:26 +0000 (13:54 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 7 Dec 2023 13:01:58 +0000 (14:01 +0100)
* initialize during declaration (if possible), unspecified fields
  defaults to zero in this case.

* fix coverity warnings:
 CID 410290:  Uninitialized variables  (UNINIT)
 Using uninitialized value "mid". Field "mid.next" is uninitialized when calling "insert_map_range".

 CID 410289:  Uninitialized variables  (UNINIT)
 Using uninitialized value "hi". Field "hi.next" is uninitialized when calling "insert_map_range".

 CID 410288:  Uninitialized variables  (UNINIT)
 Using uninitialized value "lo". Field "lo.next" is uninitialized when calling "insert_map_range".

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/unshare.c

index b03a0178aa7e84ed424532e93ac5f24a85ece6b0..ccb0834420247d314c33b3a85fb90a03e45a410e 100644 (file)
@@ -395,9 +395,7 @@ static void insert_map_range(struct map_range **chain, struct map_range map)
 static struct map_range get_map_range(const char *s)
 {
        int end;
-       struct map_range ret;
-
-       ret.next = NULL;
+       struct map_range ret = { .next = NULL };
 
        if (sscanf(s, "%u:%u:%u%n", &ret.inner, &ret.outer, &ret.count,
                   &end) >= 3 && !s[end])
@@ -424,10 +422,7 @@ static struct map_range read_subid_range(char *filename, uid_t uid)
        FILE *idmap;
        size_t n = 0;
        struct passwd *pw;
-       struct map_range map;
-
-       map.inner = -1;
-       map.next = NULL;
+       struct map_range map = { .inner = -1, .next = NULL };
 
        pw = xgetpwuid(uid, &pwbuf);
        if (!pw)
@@ -542,7 +537,8 @@ static void add_single_map_range(struct map_range **chain, unsigned int outer,
        *chain = NULL;
 
        while (map) {
-               struct map_range lo, mid, hi, *next = map->next;
+               struct map_range lo = { 0 }, mid = { 0 }, hi = { 0 },
+                                *next = map->next;
                unsigned int inner_offset, outer_offset;
 
                /*