X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FFilesystems%2FNTFS%2Fdir.c;h=dc5fb7c31691798dab57fea0140622017d23cd35;hb=56864b304e6838c84d3b94e55598b7adf4200a56;hp=17785fb78cf66e9d4566865024a4f69f9613184d;hpb=c70e02ed8cc8771daedb78507b33ab0cecebee43;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/Filesystems/NTFS/dir.c b/KernelLand/Modules/Filesystems/NTFS/dir.c index 17785fb7..dc5fb7c3 100644 --- a/KernelLand/Modules/Filesystems/NTFS/dir.c +++ b/KernelLand/Modules/Filesystems/NTFS/dir.c @@ -76,6 +76,9 @@ int NTFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) // Check allocation struct sNTFS_IndexHeader *hdr = (void*)buf; ASSERT(hdr->EntriesOffset + 0x18 < len); + // Apply update sequence + ASSERT(hdr->UpdateSequenceOfs + 2*hdr->UpdateSequenceSize <= len); + NTFS_int_ApplyUpdateSequence(buf,len, (void*)(buf+hdr->UpdateSequenceOfs), hdr->UpdateSequenceSize); size_t ofs = hdr->EntriesOffset + 0x18; ent = NTFS_int_IterateIndex(buf + ofs, len - ofs, &Pos); vcn ++; @@ -163,6 +166,10 @@ void NTFS_int_DumpIndex(tNTFS_Attrib *Allocation, Uint AttribID) while( (len = NTFS_ReadAttribData(Allocation, vcn*block_size, block_size, buf)) ) { struct sNTFS_IndexHeader *hdr = (void*)buf; + // Apply update sequence + ASSERT(hdr->UpdateSequenceOfs + 2*hdr->UpdateSequenceSize <= len); + NTFS_int_ApplyUpdateSequence(buf,len, (void*)(buf+hdr->UpdateSequenceOfs), hdr->UpdateSequenceSize); + LOG("VCN %x: Ofs=%x, Size=%x", vcn, hdr->EntriesOffset, hdr->EntriesSize); if( hdr->ThisVCN != vcn ) { @@ -312,6 +319,21 @@ tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) if( len == 0 ) break; tNTFS_IndexHeader *hdr = (void*)buf; + + if( memcmp(&hdr->Magic, "INDX", 4) != 0 ) { + Log_Notice("NTFS", "FindDir %p:%X:%x index magic bad %08x", + disk, Node->Inode, ofs / unit_len, hdr->Magic); + break; + } + // Apply update sequence + if(hdr->UpdateSequenceOfs + 2*hdr->UpdateSequenceSize > len) { + Log_Notice("NTFS", "FindDir %p:%X:%x index update sequence out of buffer (%x+%x>%x)", + disk, Node->Inode, ofs / unit_len, + hdr->UpdateSequenceOfs, 2*hdr->UpdateSequenceSize, len); + break; + } + NTFS_int_ApplyUpdateSequence(buf,len, (void*)(buf+hdr->UpdateSequenceOfs), hdr->UpdateSequenceSize); + // Search //mftent = NTFS_BTreeSearch(len, (void*)buf, NTFS_BTreeSearch_CmpI30, name16len*2, name16); mftent = NTFS_BTreeSearch( len-(hdr->EntriesOffset+0x18), buf+hdr->EntriesOffset+0x18, @@ -319,7 +341,7 @@ tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) ); } - if( !mftent ) { + if( !mftent || (mftent & (1ULL << 63)) ) { LEAVE('n'); return NULL; }