From: Karel Zak Date: Thu, 7 Dec 2023 12:54:26 +0000 (+0100) Subject: unshare: make sure map_range.next is initialized [coverity scan] X-Git-Tag: v2.40-rc1~124 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=717f267b75d79c1e94c31c76a3591df70b6a0fce;p=thirdparty%2Futil-linux.git unshare: make sure map_range.next is initialized [coverity scan] * 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 --- diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c index b03a0178aa..ccb0834420 100644 --- a/sys-utils/unshare.c +++ b/sys-utils/unshare.c @@ -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; /*