summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2009-04-29 16:38:36 +0200
committerKarel Zak <kzak@redhat.com>2009-04-29 16:38:36 +0200
commit4884729a6e5c2dbd0c7cdf356a86543525e43661 (patch)
tree7d8d7efb883cad848160ab391e4ef6bf2af82b02
parent396b8c0f9fa583b9236aadc78673ce8daa6d555b (diff)
downloadutil-linux-old-4884729a6e5c2dbd0c7cdf356a86543525e43661.tar.gz
blkid: linux_raid - fix logic for volumes with size == 0
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>
-rw-r--r--libs/blkid/src/probe.c5
-rw-r--r--libs/blkid/src/probers/linux_raid.c36
2 files changed, 25 insertions, 16 deletions
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);