From 32beec500bad9af896037a8c396e3900ae5a064e Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 14 Sep 2013 09:37:25 +0800 Subject: [PATCH] Modules/NTFS - Fixed some validation to prevent the driver crashing --- KernelLand/Modules/Filesystems/NTFS/main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/KernelLand/Modules/Filesystems/NTFS/main.c b/KernelLand/Modules/Filesystems/NTFS/main.c index 3b17e17e..18caf462 100644 --- a/KernelLand/Modules/Filesystems/NTFS/main.c +++ b/KernelLand/Modules/Filesystems/NTFS/main.c @@ -70,7 +70,11 @@ int NTFS_Detect(int FD) if( bs.BytesPerSector == 0 || (bs.BytesPerSector & 511) ) return 0; - + if( bs.SectorsPerCluster == 0 ) + return 0; + if( bs.ClustersPerMFTRecord == 0 ) + return 0; + Uint64 ncluster = bs.TotalSectorCount / bs.SectorsPerCluster; if( bs.MFTStart >= ncluster || bs.MFTMirrorStart >= ncluster ) return 0; @@ -123,6 +127,7 @@ tVFS_Node *NTFS_InitDevice(const char *Device, const char **Options) #endif disk->ClusterSize = bs.BytesPerSector * bs.SectorsPerCluster; + ASSERTR(disk->ClusterSize > 0, NULL); disk->MFTBase = bs.MFTStart; Log_Debug("NTFS", "Cluster Size = %i KiB", disk->ClusterSize/1024); Log_Debug("NTFS", "MFT Base = %i", disk->MFTBase); @@ -134,6 +139,7 @@ tVFS_Node *NTFS_InitDevice(const char *Device, const char **Options) else { disk->MFTRecSize = bs.ClustersPerMFTRecord * disk->ClusterSize; } + ASSERTR(disk->MFTRecSize > 0, NULL); //NTFS_DumpEntry(disk, 0); // $MFT //NTFS_DumpEntry(disk, 3); // $VOLUME -- 2.20.1