From: John Hodge Date: Sat, 14 Sep 2013 01:37:25 +0000 (+0800) Subject: Modules/NTFS - Fixed some validation to prevent the driver crashing X-Git-Tag: rel0.15~221 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=32beec500bad9af896037a8c396e3900ae5a064e;p=tpg%2Facess2.git Modules/NTFS - Fixed some validation to prevent the driver crashing --- 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