]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
blockdev-list: add overflow check assert
authorLuca Boccassi <luca.boccassi@gmail.com>
Fri, 17 Oct 2025 09:19:49 +0000 (10:19 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 17 Oct 2025 15:44:15 +0000 (16:44 +0100)
Fixes coverity warning

CID#1630794

src/shared/blockdev-list.c

index 16a0e2bb25c4d7add6ba8865a5168b49bed1cc86..57f80bb1115657dda46c0ba0e2e236f115f2940e 100644 (file)
@@ -111,7 +111,8 @@ int blockdev_list(BlockDevListFlags flags, BlockDevice **ret_devices, size_t *re
                         if (r < 0)
                                 log_debug_errno(r, "Failed to acquire size of device '%s', ignoring: %m", node);
                         else
-                                size *= 512; /* the 'size' sysattr is always in multiples of 512, even on 4K sector block devices! */
+                                /* the 'size' sysattr is always in multiples of 512, even on 4K sector block devices! */
+                                assert_se(MUL_ASSIGN_SAFE(&size, 512)); /* Overflow check for coverity */
 
                         if (size == 0 && FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_EMPTY)) {
                                 log_debug("Device '%s' has a zero size, assuming drive without a medium, skipping.", node);