]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
unshare: fix bad bit shift operation [coverity scan]
authorSami Kerola <kerolasa@iki.fi>
Sat, 8 Aug 2020 18:45:30 +0000 (19:45 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 16 Oct 2020 09:27:42 +0000 (11:27 +0200)
Variable cap was 32 bits and shifting it by 64 bits resulted to the shift
going over a variable boundary.

CID: 360799
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/unshare.c

index 47c468d79a97a69de0573d175df435ad057455d1..cd5fe68f8cd49e773d6a2df4a6d7e6a8aabf7094 100644 (file)
@@ -675,8 +675,7 @@ int main(int argc, char *argv[])
                };
 
                struct __user_cap_data_struct payload[_LINUX_CAPABILITY_U32S_3] = {{ 0 }};
-               int cap;
-               uint64_t effective;
+               uint64_t effective, cap;
 
                if (capget(&header, payload) < 0)
                        err(EXIT_FAILURE, _("capget failed"));
@@ -691,10 +690,10 @@ int main(int argc, char *argv[])
 
                effective = ((uint64_t)payload[1].effective << 32) |  (uint64_t)payload[0].effective;
 
-               for (cap = 0; cap < 64; cap++) {
+               for (cap = 0; cap < (sizeof(effective) * 8); cap++) {
                        /* This is the same check as cap_valid(), but using
                         * the runtime value for the last valid cap. */
-                       if (cap > cap_last_cap())
+                       if (cap > (uint64_t) cap_last_cap())
                                continue;
 
                        if ((effective & (1 << cap))