Detect exFAT filesystems and abort if found and tighten BPB sanity
check. Obtained from: Android https://android-review.googlesource.com/61827 MFC after: 2 weeks
This commit is contained in:
parent
bc6cb3f6b4
commit
6f0f107256
@ -9,6 +9,8 @@ PROG= fsck_msdosfs
|
||||
MAN= fsck_msdosfs.8
|
||||
SRCS= main.c check.c boot.c fat.c dir.c fsutil.c
|
||||
|
||||
DEBUG_FLAGS+= -g
|
||||
|
||||
CFLAGS+= -I${FSCK}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -82,6 +82,11 @@ readboot(int dosfs, struct bootblock *boot)
|
||||
|
||||
boot->FATsecs = boot->bpbFATsmall;
|
||||
|
||||
if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE_REAL != 0 ||
|
||||
boot->bpbBytesPerSec / DOSBOOTBLOCKSIZE_REAL == 0) {
|
||||
pfatal("Invalid sector size: %u", boot->bpbBytesPerSec);
|
||||
return FSFATAL;
|
||||
}
|
||||
if (!boot->bpbRootDirEnts)
|
||||
boot->flags |= FAT32;
|
||||
if (boot->flags & FAT32) {
|
||||
@ -102,6 +107,22 @@ readboot(int dosfs, struct bootblock *boot)
|
||||
boot->bpbFSInfo = block[48] + (block[49] << 8);
|
||||
boot->bpbBackup = block[50] + (block[51] << 8);
|
||||
|
||||
/* If the OEM Name field is EXFAT, it's not FAT32, so bail */
|
||||
if (!memcmp(&block[3], "EXFAT ", 8)) {
|
||||
pfatal("exFAT filesystem is not supported.");
|
||||
return FSFATAL;
|
||||
}
|
||||
|
||||
/* check basic parameters */
|
||||
if ((boot->bpbFSInfo == 0) || (boot->bpbSecPerClust == 0)) {
|
||||
/*
|
||||
* Either the BIOS Parameter Block has been corrupted,
|
||||
* or this is not a FAT32 filesystem, most likely an
|
||||
* exFAT filesystem.
|
||||
*/
|
||||
pfatal("Invalid FAT32 Extended BIOS Parameter Block");
|
||||
return FSFATAL;
|
||||
}
|
||||
if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec,
|
||||
SEEK_SET) != boot->bpbFSInfo * boot->bpbBytesPerSec
|
||||
|| read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) {
|
||||
@ -178,11 +199,6 @@ readboot(int dosfs, struct bootblock *boot)
|
||||
/* Check backup bpbFSInfo? XXX */
|
||||
}
|
||||
|
||||
if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE_REAL != 0 ||
|
||||
boot->bpbBytesPerSec == 0) {
|
||||
pfatal("Invalid sector size: %u", boot->bpbBytesPerSec);
|
||||
return FSFATAL;
|
||||
}
|
||||
if (boot->bpbSecPerClust == 0) {
|
||||
pfatal("Invalid cluster size: %u", boot->bpbSecPerClust);
|
||||
return FSFATAL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user