From: Karel Zak Date: Wed, 29 Apr 2009 14:38:36 +0000 (+0200) Subject: blkid: linux_raid - fix logic for volumes with size == 0 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4884729a6e5c2dbd0c7cdf356a86543525e43661;p=util-linux blkid: linux_raid - fix logic for volumes with size == 0 Based on commit 7643819062985d9fc6c7664072576e71d3822b10 Author: Kay Sievers Date: Sat Sep 6 16:23:21 2008 +0200 from udev upstream tree. Reported-by: Scott James Remnant Signed-off-by: Karel Zak --- diff --git a/libs/blkid/src/probe.c b/libs/blkid/src/probe.c index e6038c20..0e4745ac 100644 --- a/libs/blkid/src/probe.c +++ b/libs/blkid/src/probe.c @@ -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); diff --git a/libs/blkid/src/probers/linux_raid.c b/libs/blkid/src/probers/linux_raid.c index e21ac0a7..a5926561 100644 --- a/libs/blkid/src/probers/linux_raid.c +++ b/libs/blkid/src/probers/linux_raid.c @@ -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);