From: Samanta Navarro Date: Tue, 10 Nov 2020 10:48:04 +0000 (+0100) Subject: libblkid: limit amount of parsed partitions X-Git-Tag: v2.37-rc1~386^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c70b4f2a5b99876d230b8f4f413c3bb3ee6647f1;p=thirdparty%2Futil-linux.git libblkid: limit amount of parsed partitions The linux kernel does not support more than 256 partitions (DISK_MAX_PARTS). The atari and mac block devices have no such limits. Use dos logical partition limit for atari as well (100). Use the kernel limit for mac (256). Signed-off-by: Samanta Navarro --- diff --git a/libblkid/src/partitions/atari.c b/libblkid/src/partitions/atari.c index 3f9f4df53a..314f04763f 100644 --- a/libblkid/src/partitions/atari.c +++ b/libblkid/src/partitions/atari.c @@ -141,12 +141,16 @@ static int parse_extended(blkid_probe pr, blkid_partlist ls, blkid_parttable tab, struct atari_part_def *part) { uint32_t x0start, xstart; - unsigned i = 0; + unsigned ct = 0, i = 0; int rc; x0start = xstart = be32_to_cpu(part->start); while (1) { struct atari_rootsector *xrs; + + if (++ct > 100) + break; + xrs = (struct atari_rootsector *) blkid_probe_get_sector(pr, xstart); if (!xrs) { if (errno) diff --git a/libblkid/src/partitions/mac.c b/libblkid/src/partitions/mac.c index 2be91a6205..092d31d322 100644 --- a/libblkid/src/partitions/mac.c +++ b/libblkid/src/partitions/mac.c @@ -79,7 +79,7 @@ static int probe_mac_pt(blkid_probe pr, blkid_partlist ls; uint16_t block_size; uint16_t ssf; /* sector size fragment */ - uint32_t nblks, i; + uint32_t nblks, nprts, i; /* The driver descriptor record is always located at physical block 0, @@ -122,8 +122,15 @@ static int probe_mac_pt(blkid_probe pr, ssf = block_size / 512; nblks = be32_to_cpu(p->map_count); - - for (i = 0; i < nblks; ++i) { + if (nblks > 256) { + nprts = 256; + DBG(LOWPROBE, ul_debug( + "mac: map_count too large, entry[0]: %u, " + "enforcing limit of %u", nblks, nprts)); + } else + nprts = nblks; + + for (i = 0; i < nprts; ++i) { blkid_partition par; uint32_t start; uint32_t size; @@ -140,7 +147,7 @@ static int probe_mac_pt(blkid_probe pr, if (be32_to_cpu(p->map_count) != nblks) { DBG(LOWPROBE, ul_debug( "mac: inconsistent map_count in partition map, " - "entry[0]: %d, entry[%d]: %d", + "entry[0]: %u, entry[%u]: %u", nblks, i, be32_to_cpu(p->map_count))); }