diff --git a/fs/udf/super.c b/fs/udf/super.c index 9ac4057..b9306f8 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -667,6 +667,40 @@ out_unlock: return error; } +static int udf_is_vsd_id_valid(loff_t off, const struct volStructDesc* vsd) +{ + /* Suppose all valid identifiers are 0-9A-Z */ + int v = 1; + int i; + for (i = 0; i < sizeof(vsd->stdIdent); ++i) { + int c = vsd->stdIdent[i]; + /* isalnum(c) gives false positives, eg for 0xff */ + if ((c < '0' || c > '9') && (c < 'A' || c > 'Z')) { + v = 0; + break; + } + } +#ifdef UDFFS_DEBUG + { + char hex[sizeof(vsd->stdIdent) * 3 + 1] = { 0 }; + char chr[sizeof(vsd->stdIdent) + 1 ] = { 0 }; + char* hp = hex; + char* he = hex + sizeof(hex); + char* cp = chr; + char* ce = chr + sizeof(chr); + for (i = 0; i < sizeof(vsd->stdIdent); ++i) { + snprintf(hp, he - hp, "%02x ", vsd->stdIdent[i]); + hp += 3; + snprintf(cp, ce - cp, "%c", vsd->stdIdent[i]); + ++cp; + } + pr_notice("%s: at offset 0x%08llx vsd.stdIdent[] = { %s} : %s%s%s%s\n", __func__, off, hex, + v ? "valid" : "invalid", v ? " (" : "", v ? chr : "", v ? ")" : ""); + } +#endif + return v; +} + /* Check Volume Structure Descriptors (ECMA 167 2/9.1) */ /* We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ static loff_t udf_check_vsd(struct super_block *sb) @@ -701,7 +735,7 @@ static loff_t udf_check_vsd(struct super_block *sb) vsd = (struct volStructDesc *)(bh->b_data + (sector & (sb->s_blocksize - 1))); - if (vsd->stdIdent[0] == 0) { + if (!udf_is_vsd_id_valid(sector, vsd)) { brelse(bh); break; } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, @@ -1239,6 +1273,9 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block) * PHYSICAL partitions are already set up */ type1_idx = i; +#ifdef UDFFS_DEBUG + map = NULL; /* supress 'maybe used uninitialized' warning */ +#endif for (i = 0; i < sbi->s_partitions; i++) { map = &sbi->s_partmaps[i];