cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
05ad79
From 8125a64ff9e98d09c659dbd5adbca521d63a268b Mon Sep 17 00:00:00 2001
05ad79
From: Karel Zak <kzak@redhat.com>
05ad79
Date: Thu, 7 Jul 2016 14:22:41 +0200
05ad79
Subject: [PATCH 86/86] libblkid: avoid recursion in EBR
05ad79
05ad79
Upstream: http://github.com/karelzak/util-linux/commit/7164a1c34d18831ac61c6744ad14ce916d389b3f
05ad79
Upstream: http://github.com/karelzak/util-linux/commit/50d1594c2e6142a3b51d2143c74027480df082e0
05ad79
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1349536
05ad79
Signed-off-by: Karel Zak <kzak@redhat.com>
05ad79
---
05ad79
 libblkid/src/partitions/dos.c        | 21 +++++++++++++++++++--
05ad79
 libblkid/src/partitions/partitions.c | 14 ++++++++++++++
05ad79
 libblkid/src/partitions/partitions.h |  2 ++
05ad79
 3 files changed, 35 insertions(+), 2 deletions(-)
05ad79
05ad79
diff --git a/libblkid/src/partitions/dos.c b/libblkid/src/partitions/dos.c
05ad79
index 2d4a537..563fe9a 100644
05ad79
--- a/libblkid/src/partitions/dos.c
05ad79
+++ b/libblkid/src/partitions/dos.c
05ad79
@@ -48,6 +48,12 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab,
05ad79
 	int ct_nodata = 0;	/* count ext.partitions without data partitions */
05ad79
 	int i;
05ad79
 
05ad79
+	DBG(LOWPROBE, blkid_debug("parse EBR [start=%d, size=%d]", ex_start/ssf, ex_size/ssf));
05ad79
+	if (ex_start == 0) {
05ad79
+		DBG(LOWPROBE, blkid_debug("Bad offset in primary extended partition -- ignore"));
05ad79
+		return 0;
05ad79
+	}
05ad79
+
05ad79
 	while (1) {
05ad79
 		struct dos_partition *p, *p0;
05ad79
 		uint32_t start, size;
05ad79
@@ -100,6 +106,13 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab,
05ad79
 					continue;
05ad79
 			}
05ad79
 
05ad79
+			/* Avoid recursive non-empty links, see ct_nodata counter */
05ad79
+			if (blkid_partlist_get_partition_by_start(ls, abs_start)) {
05ad79
+				DBG(LOWPROBE, blkid_debug("#%d: EBR duplicate data partition [abs start=%u] -- ignore",
05ad79
+							i + 1, abs_start));
05ad79
+				continue;
05ad79
+			}
05ad79
+
05ad79
 			par = blkid_partlist_add_partition(ls, tab, abs_start, size);
05ad79
 			if (!par)
05ad79
 				return -ENOMEM;
05ad79
@@ -116,8 +129,12 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab,
05ad79
 			start = dos_partition_start(p) * ssf;
05ad79
 			size = dos_partition_size(p) * ssf;
05ad79
 
05ad79
-			if (size && is_extended(p))
05ad79
-				break;
05ad79
+			if (size && is_extended(p)) {
05ad79
+				if (start == 0)
05ad79
+					DBG(LOWPROBE, blkid_debug("#%d: EBR link offset is zero -- ignore", i + 1));
05ad79
+				else
05ad79
+					break;
05ad79
+			}
05ad79
 		}
05ad79
 		if (i == 4)
05ad79
 			goto leave;
05ad79
diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c
05ad79
index 752fc95..9d846ff 100644
05ad79
--- a/libblkid/src/partitions/partitions.c
05ad79
+++ b/libblkid/src/partitions/partitions.c
05ad79
@@ -928,6 +928,20 @@ blkid_partition blkid_partlist_get_partition(blkid_partlist ls, int n)
05ad79
 	return &ls->parts[n];
05ad79
 }
05ad79
 
05ad79
+blkid_partition blkid_partlist_get_partition_by_start(blkid_partlist ls, uint64_t start)
05ad79
+{
05ad79
+	int i, nparts;
05ad79
+	blkid_partition par;
05ad79
+
05ad79
+	nparts = blkid_partlist_numof_partitions(ls);
05ad79
+	for (i = 0; i < nparts; i++) {
05ad79
+		par = blkid_partlist_get_partition(ls, i);
05ad79
+		if ((uint64_t) blkid_partition_get_start(par) == start)
05ad79
+			return par;
05ad79
+	}
05ad79
+	return NULL;
05ad79
+}
05ad79
+
05ad79
 /**
05ad79
  * blkid_partlist_devno_to_partition:
05ad79
  * @ls: partitions list
05ad79
diff --git a/libblkid/src/partitions/partitions.h b/libblkid/src/partitions/partitions.h
05ad79
index 61763bf..4e99e2a 100644
05ad79
--- a/libblkid/src/partitions/partitions.h
05ad79
+++ b/libblkid/src/partitions/partitions.h
05ad79
@@ -20,6 +20,8 @@ extern int blkid_partlist_increment_partno(blkid_partlist ls);
05ad79
 
05ad79
 extern blkid_partition blkid_partlist_get_parent(blkid_partlist ls);
05ad79
 
05ad79
+extern blkid_partition blkid_partlist_get_partition_by_start(blkid_partlist ls, uint64_t start);
05ad79
+
05ad79
 extern int blkid_partitions_do_subprobe(blkid_probe pr,
05ad79
 			blkid_partition parent, const struct blkid_idinfo *id);
05ad79
 
05ad79
-- 
05ad79
2.7.4
05ad79