NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/37656: fdisk segfault on invalid MBR entries on non-x86 geometrydetection



The following reply was made to PR bin/37656; it has been noted by GNATS.

From: Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost>
To: jnemeth%victoria.tc.ca@localhost, eau%phear.org@localhost
Cc: gnats-bugs%NetBSD.org@localhost, netbsd-bugs%NetBSD.org@localhost,
        tsutsui%ceres.dti.ne.jp@localhost
Subject: Re: bin/37656: fdisk segfault on invalid MBR entries on non-x86 
geometrydetection
Date: Fri, 11 Jan 2008 20:28:07 +0900

 How about this patch?
 
 ---
 
 Index: fdisk.c
 ===================================================================
 RCS file: /cvsroot/src/sbin/fdisk/fdisk.c,v
 retrieving revision 1.113
 diff -u -r1.113 fdisk.c
 --- fdisk.c    23 Dec 2007 10:43:57 -0000      1.113
 +++ fdisk.c    11 Jan 2008 11:27:30 -0000
 @@ -1486,7 +1486,7 @@
                        a2 -= s2;
                        num = (uint64_t)h1 * a2 - (uint64_t)h2 * a1;
                        denom = (uint64_t)c2 * a1 - (uint64_t)c1 * a2;
 -                      if (denom != 0 && num % denom == 0) {
 +                      if (denom != 0 && num != 0 && num % denom == 0) {
                                xheads = num / denom;
                                xsectors = a1 / (c1 * xheads + h1);
                                break;
 @@ -1551,18 +1551,20 @@
        if (i % 2 == 0) {
                *cylinder = MBR_PCYL(part->mbrp_scyl, part->mbrp_ssect);
                *head = part->mbrp_shd;
 -              *sector = MBR_PSECT(part->mbrp_ssect) - 1;
 +              *sector = MBR_PSECT(part->mbrp_ssect);
                *absolute = le32toh(part->mbrp_start);
        } else {
                *cylinder = MBR_PCYL(part->mbrp_ecyl, part->mbrp_esect);
                *head = part->mbrp_ehd;
 -              *sector = MBR_PSECT(part->mbrp_esect) - 1;
 +              *sector = MBR_PSECT(part->mbrp_esect);
                *absolute = le32toh(part->mbrp_start)
                    + le32toh(part->mbrp_size) - 1;
        }
        /* Sanity check the data against all zeroes */
        if ((*cylinder == 0) && (*sector == 0) && (*head == 0))
                return -1;
 +      /* sector numbers in the MBR partition table start at 1 */
 +      *sector = *sector - 1;
        /* Sanity check the data against max values */
        if ((((*cylinder * MAXHEAD) + *head) * MAXSECTOR + *sector) < *absolute)
                /* cannot be a CHS mapping */
 
 
 ---
 Izumi Tsutsui
 



Home | Main Index | Thread Index | Old Index