Commit deebdf59b "fdisk: fix GPT size math errors" adjusted the
calculation of the size to multiply the number of sectors by the
sector size, but did not account for overflow: total_number_of_sectors
is uint32_t, sector_size is sector_t which is uint32_t, so simply
multiplying these resulted in a uint32_t which could overflow.
Promote the first arg to unsigned long long to avoid this.

Before, for a 1TB disk:

   # fdisk -l /dev/sda
   [   22.272680] random: nonblocking pool is initialized
   Found valid GPT with protective MBR; using GPT

   Disk /dev/sda: 1953525168 sectors, 3597M

After:

   # fdisk -l /dev/sda
   Found valid GPT with protective MBR; using GPT

   Disk /dev/sda: 1953525168 sectors,  931G

Cc: Jody Bruchon <[email protected]>
Signed-off-by: Gregory Fong <[email protected]>
---
 util-linux/fdisk_gpt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/util-linux/fdisk_gpt.c b/util-linux/fdisk_gpt.c
index 5786d5f..742d454 100644
--- a/util-linux/fdisk_gpt.c
+++ b/util-linux/fdisk_gpt.c
@@ -93,7 +93,8 @@ gpt_list_table(int xtra UNUSED_PARAM)
        int i;
        char numstr6[6];
 
-       smart_ulltoa5(total_number_of_sectors * sector_size, numstr6, " 
KMGTPEZY")[0] = '\0';
+       smart_ulltoa5((unsigned long long)total_number_of_sectors *
+               sector_size, numstr6, " KMGTPEZY")[0] = '\0';
        printf("Disk %s: %llu sectors, %s\n", disk_device,
                (unsigned long long)total_number_of_sectors,
                numstr6);
-- 
1.9.1

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to