]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: limit amount of parsed partitions
authorSamanta Navarro <ferivoz@riseup.net>
Tue, 10 Nov 2020 10:48:04 +0000 (11:48 +0100)
committerSamanta Navarro <ferivoz@riseup.net>
Tue, 10 Nov 2020 11:53:16 +0000 (11:53 +0000)
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 <ferivoz@riseup.net>
libblkid/src/partitions/atari.c
libblkid/src/partitions/mac.c

index 3f9f4df53acd0fc50812b01f5879219aad3e20ef..314f04763fa16be4f8a81f3f7e294100d4a7e581 100644 (file)
@@ -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)
index 2be91a6205c6d52a264c9707e52a292c2d863bd2..092d31d322f2cf8863d944d1f6aa4bf4e076be9d 100644 (file)
@@ -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)));
                }