forked from len0rd/rockbox
fat: Validate FS Info Sector signature when attempting to mount volume
The "try to mount as superfloppy" fails with some partitioning layouts because sector 0 can have a mostly-valid FAT32 signature. However, in all dumps I've looked at, sector 0's fsinfo offset value points at a place which lacks the fsinfo signature. Resolves FS#13213, no known regressions. Change-Id: Ib323d35cca6ca54e11aca6ba77041bf33a05a277
This commit is contained in:
parent
aa20b6af7a
commit
7249fabe63
1 changed files with 11 additions and 0 deletions
|
@ -178,9 +178,12 @@ struct fsinfo
|
|||
clusters, or 0xffffffff for no hint */
|
||||
};
|
||||
/* fsinfo offsets */
|
||||
#define FSINFO_SIGNATURE 0
|
||||
#define FSINFO_FREECOUNT 488
|
||||
#define FSINFO_NEXTFREE 492
|
||||
|
||||
#define FSINFO_SIGNATURE_VAL 0x41615252
|
||||
|
||||
#ifdef HAVE_FAT16SUPPORT
|
||||
#define BPB_FN_SET16(bpb, fn) (bpb)->fn##__ = fn##16
|
||||
#define BPB_FN_SET32(bpb, fn) (bpb)->fn##__ = fn##32
|
||||
|
@ -1251,6 +1254,14 @@ static int fat_mount_internal(struct bpb *fat_bpb)
|
|||
FAT_ERROR(rc * 10 - 8);
|
||||
}
|
||||
|
||||
/* Sanity check FS info */
|
||||
long info = BYTES2INT32(buf, FSINFO_SIGNATURE);
|
||||
if (info != FSINFO_SIGNATURE_VAL) {
|
||||
DEBUGF("%S() FSInfo signature mismatch (%x)\n",
|
||||
__func__, info);
|
||||
FAT_ERROR(-9);
|
||||
}
|
||||
|
||||
fat_bpb->fsinfo.freecount = BYTES2INT32(buf, FSINFO_FREECOUNT);
|
||||
fat_bpb->fsinfo.nextfree = BYTES2INT32(buf, FSINFO_NEXTFREE);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue