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

commit 79794b524cd9b865113dc9c254d06f82b3b161ae
Author:     Doug Lyons <[email protected]>
AuthorDate: Sat Sep 26 17:39:15 2020 -0500
Commit:     Stanislav Motylkov <[email protected]>
CommitDate: Mon Oct 12 18:54:06 2020 +0300

    [FASTFAT] Fix create for DOT and DOT-DOT leaving bad directory entry (#3241)
---
 drivers/filesystems/fastfat/create.c | 11 ++++++++---
 drivers/filesystems/fastfat/finfo.c  | 10 +++++++---
 drivers/filesystems/fastfat/string.c | 10 +++++++++-
 drivers/filesystems/fastfat/vfat.h   |  4 ++++
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/drivers/filesystems/fastfat/create.c 
b/drivers/filesystems/fastfat/create.c
index aadc990e37b..0de08a9dd78 100644
--- a/drivers/filesystems/fastfat/create.c
+++ b/drivers/filesystems/fastfat/create.c
@@ -360,9 +360,7 @@ VfatOpenFile(
         return STATUS_CANNOT_DELETE;
     }
 
-    if ((vfatFCBIsRoot(Fcb) ||
-         (Fcb->LongNameU.Length == sizeof(WCHAR) && Fcb->LongNameU.Buffer[0] 
== L'.') ||
-         (Fcb->LongNameU.Length == 2 * sizeof(WCHAR) && 
Fcb->LongNameU.Buffer[0] == L'.' && Fcb->LongNameU.Buffer[1] == L'.')) &&
+    if ((vfatFCBIsRoot(Fcb) || IsDotOrDotDot(&Fcb->LongNameU)) &&
         BooleanFlagOn(RequestedOptions, FILE_DELETE_ON_CLOSE))
     {
         // we cannot delete a '.', '..' or the root directory
@@ -791,6 +789,13 @@ VfatCreateFile(
                 Attributes |= FILE_ATTRIBUTE_ARCHIVE;
             }
             vfatSplitPathName(&PathNameU, NULL, &FileNameU);
+
+            if (IsDotOrDotDot(&FileNameU))
+            {
+                vfatReleaseFCB(DeviceExt, ParentFcb);
+                vfatAddToStat(DeviceExt, Fat.FailedCreates, 1);
+                return STATUS_OBJECT_NAME_INVALID;
+            }
             Status = VfatAddEntry(DeviceExt, &FileNameU, &pFcb, ParentFcb, 
RequestedOptions,
                                   Attributes, NULL);
             vfatReleaseFCB(DeviceExt, ParentFcb);
diff --git a/drivers/filesystems/fastfat/finfo.c 
b/drivers/filesystems/fastfat/finfo.c
index 755ba6a9917..49738122b1e 100644
--- a/drivers/filesystems/fastfat/finfo.c
+++ b/drivers/filesystems/fastfat/finfo.c
@@ -380,9 +380,7 @@ VfatSetDispositionInformation(
         return STATUS_CANNOT_DELETE;
     }
 
-    if (vfatFCBIsRoot(FCB) ||
-        (FCB->LongNameU.Length == sizeof(WCHAR) && FCB->LongNameU.Buffer[0] == 
L'.') ||
-        (FCB->LongNameU.Length == 2 * sizeof(WCHAR) && 
FCB->LongNameU.Buffer[0] == L'.' && FCB->LongNameU.Buffer[1] == L'.'))
+    if (vfatFCBIsRoot(FCB) || IsDotOrDotDot(&FCB->LongNameU))
     {
         /* we cannot delete a '.', '..' or the root directory */
         return STATUS_ACCESS_DENIED;
@@ -804,6 +802,12 @@ VfatSetRenameInformation(
     vfatSplitPathName(&NewName, &NewPath, &NewFile);
     DPRINT("New dir: %wZ, New file: %wZ\n", &NewPath, &NewFile);
 
+    if (IsDotOrDotDot(&NewFile))
+    {
+        Status = STATUS_OBJECT_NAME_INVALID;
+        goto Cleanup;
+    }
+
     if (vfatFCBIsDirectory(FCB) && !IsListEmpty(&FCB->ParentListHead))
     {
         if (IsThereAChildOpened(FCB))
diff --git a/drivers/filesystems/fastfat/string.c 
b/drivers/filesystems/fastfat/string.c
index 6a8f65a48f5..00b3271c921 100644
--- a/drivers/filesystems/fastfat/string.c
+++ b/drivers/filesystems/fastfat/string.c
@@ -3,7 +3,8 @@
  * PROJECT:          ReactOS kernel
  * FILE:             drivers/fs/vfat/string.c
  * PURPOSE:          VFAT Filesystem
- * PROGRAMMER:       Jason Filby ([email protected])
+ * PROGRAMMERS:      Jason Filby ([email protected])
+ *                   Doug Lyons (douglyons at douglyons dot com)
  *
  */
 
@@ -24,3 +25,10 @@ vfatIsLongIllegal(
 {
     return wcschr(long_illegals, c) ? TRUE : FALSE;
 }
+
+BOOLEAN
+IsDotOrDotDot(PCUNICODE_STRING Name)
+{
+    return ((Name->Length == sizeof(WCHAR) && Name->Buffer[0] == L'.') ||
+        (Name->Length == 2 * sizeof(WCHAR) && Name->Buffer[0] == L'.' && 
Name->Buffer[1] == L'.'));
+}
diff --git a/drivers/filesystems/fastfat/vfat.h 
b/drivers/filesystems/fastfat/vfat.h
index 478753447d0..593ceb7c2da 100644
--- a/drivers/filesystems/fastfat/vfat.h
+++ b/drivers/filesystems/fastfat/vfat.h
@@ -1221,6 +1221,10 @@ BOOLEAN
 vfatIsLongIllegal(
     WCHAR c);
 
+BOOLEAN
+IsDotOrDotDot(
+    PCUNICODE_STRING Name);
+
 /* volume.c */
 
 NTSTATUS

Reply via email to