From: Rostislav Skudnov Date: Tue, 30 Aug 2016 10:07:49 +0000 (+0000) Subject: libblkid: [exfat] Limit maximum number of iterations in find_label X-Git-Tag: v2.28.2~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=246940c51301e1b17487594adab8ab5101223d46;p=thirdparty%2Futil-linux.git libblkid: [exfat] Limit maximum number of iterations in find_label Do not hang if there is a cluster chain loop in rootdir [kzak@redhat.com: - add return NULL] Signed-off-by: Karel Zak --- diff --git a/libblkid/src/superblocks/exfat.c b/libblkid/src/superblocks/exfat.c index 01ed30b788..659e196c2d 100644 --- a/libblkid/src/superblocks/exfat.c +++ b/libblkid/src/superblocks/exfat.c @@ -86,8 +86,10 @@ static struct exfat_entry_label *find_label(blkid_probe pr, uint32_t cluster = le32_to_cpu(sb->rootdir_cluster); uint64_t offset = cluster_to_offset(sb, cluster); uint8_t *entry; + const size_t max_iter = 10000; + size_t i = 0; - for (;;) { + for (; i < max_iter; i++) { entry = (uint8_t *) blkid_probe_get_buffer(pr, offset, EXFAT_ENTRY_SIZE); if (!entry) @@ -96,6 +98,7 @@ static struct exfat_entry_label *find_label(blkid_probe pr, return NULL; if (entry[0] == EXFAT_ENTRY_LABEL) return (struct exfat_entry_label *) entry; + offset += EXFAT_ENTRY_SIZE; if (offset % CLUSTER_SIZE(sb) == 0) { cluster = next_cluster(pr, sb, cluster); @@ -106,6 +109,8 @@ static struct exfat_entry_label *find_label(blkid_probe pr, offset = cluster_to_offset(sb, cluster); } } + + return NULL; } static int probe_exfat(blkid_probe pr, const struct blkid_idmag *mag)