]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: [exfat] Limit maximum number of iterations in find_label
authorRostislav Skudnov <rostislav@tuxera.com>
Tue, 30 Aug 2016 10:07:49 +0000 (10:07 +0000)
committerKarel Zak <kzak@redhat.com>
Tue, 30 Aug 2016 11:50:51 +0000 (13:50 +0200)
Do not hang if there is a cluster chain loop in rootdir

[kzak@redhat.com: - add return NULL]

Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/superblocks/exfat.c

index 01ed30b788c1890c207f36716a409f477b34e61f..659e196c2dd965234ef1be126c3b2c7c05b3cf93 100644 (file)
@@ -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)