]> err.no Git - util-linux/commitdiff
blkid: linux_raid - fix logic for volumes with size == 0
authorKarel Zak <kzak@redhat.com>
Wed, 29 Apr 2009 14:38:36 +0000 (16:38 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 29 Apr 2009 14:38:36 +0000 (16:38 +0200)
 Based on

    commit 7643819062985d9fc6c7664072576e71d3822b10
    Author: Kay Sievers <kay.sievers@vrfy.org>
    Date:   Sat Sep 6 16:23:21 2008 +0200

 from udev upstream tree.

Reported-by: Scott James Remnant <scott@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libs/blkid/src/probe.c
libs/blkid/src/probers/linux_raid.c

index e6038c2069bae8eca2d1828e7f167a4179f60be0..0e4745acaff15222f6841c32048e8084d41fde25 100644 (file)
@@ -196,6 +196,11 @@ unsigned char *blkid_probe_get_buffer(blkid_probe pr,
 {
        ssize_t ret_read = 0;
 
+       if (off < 0 || len < 0) {
+               DBG(DEBUG_LOWPROBE,
+                       printf("unexpected offset or length of buffer requested\n"));
+               return NULL;
+       }
        if (off + len <= BLKID_SB_BUFSIZ) {
                if (!pr->sbbuf) {
                        pr->sbbuf = malloc(BLKID_SB_BUFSIZ);
index e21ac0a7ccbf40d1fca4218f611ca63fbce7de30..a5926561d317c02d51d91fa62d46830af572eaf4 100644 (file)
@@ -125,25 +125,29 @@ static int probe_raid1(blkid_probe pr, off_t off)
 int probe_raid(blkid_probe pr, const struct blkid_idmag *mag)
 {
        const char *ver = NULL;
-       uint64_t sboff;
 
-       /* version 0 at the end of the device */
-       sboff = (pr->size & ~(MD_RESERVED_BYTES - 1)) - MD_RESERVED_BYTES;
-       if (probe_raid0(pr, sboff) == 0)
-               return 0;
-
-       /* version 1.0 at the end of the device */
-       sboff = (pr->size & ~(0x1000 - 1)) - 0x2000;
-       if (probe_raid1(pr, sboff) == 0)
-               ver = "1.0";
+       if (pr->size > MD_RESERVED_BYTES) {
+               /* version 0 at the end of the device */
+               uint64_t sboff = (pr->size & ~(MD_RESERVED_BYTES - 1))
+                                - MD_RESERVED_BYTES;
+               if (probe_raid0(pr, sboff) == 0)
+                       return 0;
+
+               /* version 1.0 at the end of the device */
+               sboff = (pr->size & ~(0x1000 - 1)) - 0x2000;
+               if (probe_raid1(pr, sboff) == 0)
+                       ver = "1.0";
+       }
 
-       /* version 1.1 at the start of the device */
-       else if (probe_raid1(pr, 0) == 0)
-               ver = "1.1";
+       if (!ver) {
+               /* version 1.1 at the start of the device */
+               if (probe_raid1(pr, 0) == 0)
+                       ver = "1.1";
 
-       /* version 1.2 at 4k offset from the start */
-       else if (probe_raid1(pr, 0x1000) == 0)
-               ver = "1.2";
+               /* version 1.2 at 4k offset from the start */
+               else if (probe_raid1(pr, 0x1000) == 0)
+                       ver = "1.2";
+       }
 
        if (ver) {
                blkid_probe_set_version(pr, ver);