https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f5b7f90f237d6d21249c203753d9c8c1e65ab84f

commit f5b7f90f237d6d21249c203753d9c8c1e65ab84f
Author: Trevor Thompson <[email protected]>
AuthorDate: Tue Jul 4 21:16:46 2017 +0000

    [NTFS] - Fix UpdateFileNameRecord() when the file being updated resides in 
$INDEX_ROOT. Also, don't attempt to read beyond size of index root attribute, 
and check return value after reading.
    
    svn path=/branches/GSoC_2016/NTFS/; revision=75278
---
 drivers/filesystems/ntfs/mft.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/filesystems/ntfs/mft.c b/drivers/filesystems/ntfs/mft.c
index 6ffe8d53ad..f8aff9ccd2 100644
--- a/drivers/filesystems/ntfs/mft.c
+++ b/drivers/filesystems/ntfs/mft.c
@@ -1418,7 +1418,15 @@ UpdateFileNameRecord(PDEVICE_EXTENSION Vcb,
         return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-    ReadAttribute(Vcb, IndexRootCtx, 0, IndexRecord, 
Vcb->NtfsInfo.BytesPerIndexRecord);
+    Status = ReadAttribute(Vcb, IndexRootCtx, 0, IndexRecord, 
AttributeDataLength(&IndexRootCtx->Record));
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("ERROR: Failed to read Index Root!\n");
+        ExFreePoolWithTag(IndexRecord, TAG_NTFS);
+        ReleaseAttributeContext(IndexRootCtx);
+        ExFreePoolWithTag(MftRecord, TAG_NTFS);
+    }
+
     IndexRoot = (PINDEX_ROOT_ATTRIBUTE)IndexRecord;
     IndexEntry = (PINDEX_ENTRY_ATTRIBUTE)((PCHAR)&IndexRoot->Header + 
IndexRoot->Header.FirstEntryOffset);
     // Index root is always resident. 
@@ -1440,6 +1448,18 @@ UpdateFileNameRecord(PDEVICE_EXTENSION Vcb,
                                           NewAllocationSize,
                                           CaseSensitive);
 
+    if (Status == STATUS_PENDING)
+    {
+        // we need to write the index root attribute back to disk
+        ULONG LengthWritten;
+        Status = WriteAttribute(Vcb, IndexRootCtx, 0, IndexRecord, 
AttributeDataLength(&IndexRootCtx->Record), &LengthWritten);
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT1("ERROR: Couldn't update Index Root!\n");
+        }
+
+    }
+
     ReleaseAttributeContext(IndexRootCtx);
     ExFreePoolWithTag(IndexRecord, TAG_NTFS);
     ExFreePoolWithTag(MftRecord, TAG_NTFS);

Reply via email to