From 7f2b7ec93c347ef81cb6048c6895b967feaa2260 Mon Sep 17 00:00:00 2001 From: Xin LI Date: Fri, 13 Jul 2018 02:02:16 +0000 Subject: [PATCH] Detect and handle invalid number of FATs If the number of FATs field in the boot sector is zero, give an appropriate error code. Obtained from: Android https://android.googlesource.com/platform/external/fsck_msdos/+/6c29bbe8d58e6fe8755935a04166ecf82ff31f47%5E%21/ MFC after: 2 weeks --- sbin/fsck_msdosfs/boot.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sbin/fsck_msdosfs/boot.c b/sbin/fsck_msdosfs/boot.c index 9a954d07ae9..9e0958a9454 100644 --- a/sbin/fsck_msdosfs/boot.c +++ b/sbin/fsck_msdosfs/boot.c @@ -87,6 +87,10 @@ readboot(int dosfs, struct bootblock *boot) pfatal("Invalid sector size: %u", boot->bpbBytesPerSec); return FSFATAL; } + if (boot->bpbFATs == 0) { + pfatal("Invalid number of FATs: %u", boot->bpbFATs); + return FSFATAL; + } if (!boot->bpbRootDirEnts) boot->flags |= FAT32; if (boot->flags & FAT32) {