[kpartx] bug fixes for dos extended partition [3/4]
authorChristophe Varoqui <root@xa-s05.(none)>
Thu, 1 Dec 2005 20:57:29 +0000 (21:57 +0100)
committerChristophe Varoqui <root@xa-s05.(none)>
Thu, 1 Dec 2005 20:57:29 +0000 (21:57 +0100)
in the for loop in read_extended_partition,
'here' is updated if the next extended partition is found.

However, the 'here' value should be updated in the next while loop.
Otherwise it's possible that following partition table
entry refers updated value and generate wrong mapping.

I'm not sure if there is any partitioning tool which can generate
such table. But it's safer to fix this.

Jun'ichi Nomura, NEC

kpartx/dos.c

index ffa0f84..ce001a7 100644 (file)
@@ -20,15 +20,16 @@ read_extended_partition(int fd, struct partition *ep,
                        struct slice *sp, int ns)
 {
        struct partition p;
-       unsigned long start, here;
+       unsigned long start, here, next;
        unsigned char *bp;
        int loopct = 0;
        int moretodo = 1;
        int i, n=0;
 
-       here = start = le32_to_cpu(ep->start_sect);
+       next = start = le32_to_cpu(ep->start_sect);
 
        while (moretodo) {
+               here = next;
                moretodo = 0;
                if (++loopct > 100)
                        return n;
@@ -43,8 +44,8 @@ read_extended_partition(int fd, struct partition *ep,
                for (i=0; i<2; i++) {
                        memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p));
                        if (is_extended(p.sys_type)) {
-                               if (p.nr_sects) {
-                                       here = start + le32_to_cpu(p.start_sect);
+                               if (p.nr_sects && !moretodo) {
+                                       next = start + le32_to_cpu(p.start_sect);
                                        moretodo = 1;
                                }
                                continue;