]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sfdisk: fix calculation due to type mismatch (ix86)
authorPetr Uzel <petr.uzel@suse.cz>
Fri, 6 Apr 2012 14:53:13 +0000 (16:53 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 24 May 2012 11:58:27 +0000 (13:58 +0200)
Instructing sfdisk to create one partition spanning
across entire disk (",,") on 32bit system, if the disk
is sufficiently large (~2TB) leads to wrong calculation
in compute_start_sect() due to type mismatch.

Can be reproduced as:

--------------------------
linux-3ln5:~ # modprobe scsi_debug virtual_gb=2000
linux-3ln5:~ # sfdisk /dev/sda <<< ',,'
Checking that no-one is using this disk right now ...
OK

Disk /dev/sda: 261083 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
sfdisk:  /dev/sda: unrecognized partition table type

Old situation:
sfdisk: No partitions found

no room for partition descriptor
sfdisk: bad input
--------------------------

Addresses: https://bugzilla.novell.com/show_bug.cgi?id=754789
Reported-by: Dan Mares <dan.mares@norcrossgroup.com>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
fdisk/sfdisk.c

index 6267652ffee9650bad2c4c0414d131e95fdd5e97..f941bb46cd7ad16da422c310859e2a8541751696 100644 (file)
@@ -1990,7 +1990,7 @@ static int
 compute_start_sect(struct part_desc *p, struct part_desc *ep) {
     unsigned long long base;
     int inc = (DOS && B.sectors) ? B.sectors : 1;
-    int delta;
+    long long delta;
 
     if (ep && p->start + p->size >= ep->start + 1)
        delta = p->start - ep->start - inc;
@@ -2005,7 +2005,7 @@ compute_start_sect(struct part_desc *p, struct part_desc *ep) {
        p->size += delta;
        if (is_extended(p->p.sys_type) && boxes == ONESECTOR)
            p->size = inc;
-       else if ((ssize_t) old_size <= (ssize_t) - delta) {
+       else if ((long long) old_size <= -delta) {
            my_warn(_("no room for partition descriptor\n"));
            return 0;
        }