cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
3d071d
From 24f5385f4a54b90f4b7674e23f30567591962bcb Mon Sep 17 00:00:00 2001
3d071d
From: Samanta Navarro <ferivoz@riseup.net>
3d071d
Date: Tue, 10 Nov 2020 11:48:04 +0100
3d071d
Subject: libblkid: limit amount of parsed partitions
3d071d
3d071d
The linux kernel does not support more than 256 partitions
3d071d
(DISK_MAX_PARTS). The atari and mac block devices have no such limits.
3d071d
3d071d
Use dos logical partition limit for atari as well (100).
3d071d
Use the kernel limit for mac (256).
3d071d
3d071d
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2060030
3d071d
Upstream: http://github.com/util-linux/util-linux/commit/c70b4f2a5b99876d230b8f4f413c3bb3ee6647f1
3d071d
Signed-off-by: Karel Zak <kzak@redhat.com>
3d071d
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
3d071d
---
3d071d
 libblkid/src/partitions/atari.c |  6 +++++-
3d071d
 libblkid/src/partitions/mac.c   | 15 +++++++++++----
3d071d
 2 files changed, 16 insertions(+), 5 deletions(-)
3d071d
3d071d
diff --git a/libblkid/src/partitions/atari.c b/libblkid/src/partitions/atari.c
3d071d
index c3f77117a..fdd5498b5 100644
3d071d
--- a/libblkid/src/partitions/atari.c
3d071d
+++ b/libblkid/src/partitions/atari.c
3d071d
@@ -141,12 +141,16 @@ static int parse_extended(blkid_probe pr, blkid_partlist ls,
3d071d
 	blkid_parttable tab, struct atari_part_def *part)
3d071d
 {
3d071d
 	uint32_t x0start, xstart;
3d071d
-	unsigned i = 0;
3d071d
+	unsigned ct = 0, i = 0;
3d071d
 	int rc;
3d071d
 
3d071d
 	x0start = xstart = be32_to_cpu(part->start);
3d071d
 	while (1) {
3d071d
 		struct atari_rootsector *xrs;
3d071d
+
3d071d
+		if (++ct > 100)
3d071d
+			break;
3d071d
+
3d071d
 		xrs = (struct atari_rootsector *) blkid_probe_get_sector(pr, xstart);
3d071d
 		if (!xrs) {
3d071d
 			if (errno)
3d071d
diff --git a/libblkid/src/partitions/mac.c b/libblkid/src/partitions/mac.c
3d071d
index 2be91a620..092d31d32 100644
3d071d
--- a/libblkid/src/partitions/mac.c
3d071d
+++ b/libblkid/src/partitions/mac.c
3d071d
@@ -79,7 +79,7 @@ static int probe_mac_pt(blkid_probe pr,
3d071d
 	blkid_partlist ls;
3d071d
 	uint16_t block_size;
3d071d
 	uint16_t ssf;	/* sector size fragment */
3d071d
-	uint32_t nblks, i;
3d071d
+	uint32_t nblks, nprts, i;
3d071d
 
3d071d
 
3d071d
 	/* The driver descriptor record is always located at physical block 0,
3d071d
@@ -122,8 +122,15 @@ static int probe_mac_pt(blkid_probe pr,
3d071d
 
3d071d
 	ssf = block_size / 512;
3d071d
 	nblks = be32_to_cpu(p->map_count);
3d071d
-
3d071d
-	for (i = 0; i < nblks; ++i) {
3d071d
+	if (nblks > 256) {
3d071d
+		nprts = 256;
3d071d
+		DBG(LOWPROBE, ul_debug(
3d071d
+			"mac: map_count too large, entry[0]: %u, "
3d071d
+			"enforcing limit of %u", nblks, nprts));
3d071d
+	} else
3d071d
+		nprts = nblks;
3d071d
+
3d071d
+	for (i = 0; i < nprts; ++i) {
3d071d
 		blkid_partition par;
3d071d
 		uint32_t start;
3d071d
 		uint32_t size;
3d071d
@@ -140,7 +147,7 @@ static int probe_mac_pt(blkid_probe pr,
3d071d
 		if (be32_to_cpu(p->map_count) != nblks) {
3d071d
 			DBG(LOWPROBE, ul_debug(
3d071d
 				"mac: inconsistent map_count in partition map, "
3d071d
-				"entry[0]: %d, entry[%d]: %d",
3d071d
+				"entry[0]: %u, entry[%u]: %u",
3d071d
 				nblks, i,
3d071d
 				be32_to_cpu(p->map_count)));
3d071d
 		}
3d071d
-- 
3d071d
2.36.1
3d071d