Skip to content

boof#23

Draft
Chuccle wants to merge 3 commits into
masterfrom
inverted
Draft

boof#23
Chuccle wants to merge 3 commits into
masterfrom
inverted

Conversation

@Chuccle
Copy link
Copy Markdown
Owner

@Chuccle Chuccle commented Jul 1, 2025

No description provided.

@Chuccle Chuccle marked this pull request as draft July 1, 2025 22:11
Comment thread InvertedCallWorkQueue.c Fixed
Comment thread InvertedCallWorkQueue.c Fixed
@Chuccle Chuccle force-pushed the inverted branch 27 times, most recently from 76a2ef2 to e0cb46b Compare July 25, 2025 23:09
@Chuccle Chuccle force-pushed the inverted branch 9 times, most recently from c1764fe to 0013783 Compare July 27, 2025 00:26
@Chuccle Chuccle force-pushed the inverted branch 4 times, most recently from 467da90 to 3cd88ad Compare August 11, 2025 23:33
@Chuccle Chuccle force-pushed the inverted branch 6 times, most recently from 0afd57f to 219a440 Compare August 17, 2025 22:06
Comment thread InvertedCallWorkQueue.c Fixed
Comment thread InvertedCallWorkQueue.c Fixed
@Chuccle Chuccle force-pushed the inverted branch 2 times, most recently from 219a440 to 2209123 Compare August 17, 2025 23:22
Comment thread DirCtrl.c
Comment on lines +456 to +560
switch (irpSp->Parameters.QueryDirectory.FileInformationClass)
{
case FileIdBothDirectoryInformation:
{
PFILE_ID_BOTH_DIR_INFORMATION dirInfo = (!Request->OriginalIrp->MdlAddress) ?
Request->OriginalIrp->UserBuffer :
MmGetSystemAddressForMdlSafe(Request->OriginalIrp->MdlAddress, NormalPagePriority | MdlMappingNoExecute);

if (!dirInfo)
{
result = STATUS_INSUFFICIENT_RESOURCES;
break;
}

if (!Request->OriginalIrp->MdlAddress && UserMode == Request->OriginalIrp->RequestorMode)
{
ProbeForRead(Request->OriginalIrp->UserBuffer, irpSp->Parameters.QueryDirectory.Length, sizeof(UCHAR));
}

SIZE_T used = 0;
result = EnumerateDirectoryEntries(
ccb,
index,
totalEntries,
&ccb->SearchPattern,
ccb->Flags,
returnSingleEntry,
dirInfo,
remainingLength,
FillFileIdBothDirInfo,
&used,
&index
);

if (NT_SUCCESS(result))
{
Request->OriginalIrp->IoStatus.Information = used;
}

updateCcb = !indexSpecified;
break;
}
case FileDirectoryInformation:
{
result = STATUS_NOT_IMPLEMENTED;
break;
}
case FileFullDirectoryInformation:
{
PFILE_FULL_DIR_INFORMATION dirInfo = (!Request->OriginalIrp->MdlAddress) ? Request->OriginalIrp->UserBuffer : MmGetSystemAddressForMdlSafe(Request->OriginalIrp->MdlAddress, NormalPagePriority | MdlMappingNoExecute);

if (!dirInfo)
{
result = STATUS_INSUFFICIENT_RESOURCES;
break;
}

if (!Request->OriginalIrp->MdlAddress && UserMode == Request->OriginalIrp->RequestorMode)
{
ProbeForRead(Request->OriginalIrp->UserBuffer, irpSp->Parameters.QueryDirectory.Length, sizeof(UCHAR));
}

SIZE_T used = 0;
result = EnumerateDirectoryEntries(
ccb,
index,
totalEntries,
&ccb->SearchPattern,
ccb->Flags,
returnSingleEntry,
dirInfo,
remainingLength,
FillFileFullDirInfo,
&used,
&index
);

if (NT_SUCCESS(result))
{
Request->OriginalIrp->IoStatus.Information = used;
}

updateCcb = !indexSpecified;
break;
}
case FileIdFullDirectoryInformation:
{
result = STATUS_NOT_IMPLEMENTED;
break;
}
case FileNamesInformation:
{
result = STATUS_NOT_IMPLEMENTED;
break;
}
case FileBothDirectoryInformation:
{
result = STATUS_NOT_IMPLEMENTED;
break;
}
default:
{
result = STATUS_INVALID_INFO_CLASS;
}
}

Check notice

Code scanning / CodeQL

Long switch case Note

Switch has at least one case that is too long:
FileIdBothDirectoryInformation (39 lines)
.
Switch has at least one case that is too long:
FileFullDirectoryInformation (37 lines)
.

Copilot Autofix

AI 7 months ago

To fix the issue, the code inside the FileIdBothDirectoryInformation case (lines 459-496) should be extracted into a separate static helper function. This function should take all parameters required to perform the same logic, including setting the result, and an indication if updateCcb should be set. The switch will then invoke the helper function, and the case block will become a one-liner.

In practice:

  • The 39 lines inside case FileIdBothDirectoryInformation: should be replaced by a call to a new static function, e.g., ProcessFileIdBothDirInfo(...).
  • The function will be defined within DirCtrl.c, directly above the switch, taking arguments: pointers to relevant objects/structs (Request, ccb, irpSp), state variables (indexSpecified, returnSingleEntry, etc.), and references for return values (result, updateCcb, etc.).
  • This function will encapsulate the logic for probing memory, enumerating directory entries, and updating status.
  • No new dependencies are needed; only local rearrangement and static function addition.

You should only edit DirCtrl.c within code snippets you have seen, and insert the new function just before the switch block.


Suggested changeset 1
DirCtrl.c

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/DirCtrl.c b/DirCtrl.c
--- a/DirCtrl.c
+++ b/DirCtrl.c
@@ -451,48 +451,77 @@
 
     ULONG totalEntries = C_CAST(ULONG, ccb->Entries->FileCount + ccb->Entries->SubDirCount);
 
+
+    // Helper to process FileIdBothDirectoryInformation case
+    static void ProcessFileIdBothDirInfo(
+        PIRP_CONTEXT Request,
+        PCCB ccb,
+        PIO_STACK_LOCATION irpSp,
+        ULONG totalEntries,
+        BOOLEAN returnSingleEntry,
+        ULONG remainingLength,
+        BOOLEAN indexSpecified,
+        ULONG* pIndex,
+        NTSTATUS* pResult,
+        BOOLEAN* pUpdateCcb
+    )
+    {
+        PFILE_ID_BOTH_DIR_INFORMATION dirInfo = (!Request->OriginalIrp->MdlAddress) ?
+            Request->OriginalIrp->UserBuffer :
+            MmGetSystemAddressForMdlSafe(Request->OriginalIrp->MdlAddress, NormalPagePriority | MdlMappingNoExecute);
+
+        if (!dirInfo)
+        {
+            *pResult = STATUS_INSUFFICIENT_RESOURCES;
+            return;
+        }
+
+        if (!Request->OriginalIrp->MdlAddress && UserMode == Request->OriginalIrp->RequestorMode)
+        {
+            ProbeForRead(Request->OriginalIrp->UserBuffer, irpSp->Parameters.QueryDirectory.Length, sizeof(UCHAR));
+        }
+
+        SIZE_T used = 0;
+        *pResult = EnumerateDirectoryEntries(
+            ccb,
+            *pIndex,
+            totalEntries,
+            &ccb->SearchPattern,
+            ccb->Flags,
+            returnSingleEntry,
+            dirInfo,
+            remainingLength,
+            FillFileIdBothDirInfo,
+            &used,
+            pIndex
+        );
+
+        if (NT_SUCCESS(*pResult))
+        {
+            Request->OriginalIrp->IoStatus.Information = used;
+        }
+
+        *pUpdateCcb = !indexSpecified;
+    }
+
     __try
     {
         switch (irpSp->Parameters.QueryDirectory.FileInformationClass)
         {
             case FileIdBothDirectoryInformation:
             {
-                PFILE_ID_BOTH_DIR_INFORMATION dirInfo = (!Request->OriginalIrp->MdlAddress) ?
-                    Request->OriginalIrp->UserBuffer :
-                    MmGetSystemAddressForMdlSafe(Request->OriginalIrp->MdlAddress, NormalPagePriority | MdlMappingNoExecute);
-
-                if (!dirInfo)
-                {
-                    result = STATUS_INSUFFICIENT_RESOURCES;
-                    break;
-                }
-
-                if (!Request->OriginalIrp->MdlAddress && UserMode == Request->OriginalIrp->RequestorMode)
-                {
-                    ProbeForRead(Request->OriginalIrp->UserBuffer, irpSp->Parameters.QueryDirectory.Length, sizeof(UCHAR));
-                }
-
-                SIZE_T used = 0;
-                result = EnumerateDirectoryEntries(
+                ProcessFileIdBothDirInfo(
+                    Request,
                     ccb,
-                    index,
+                    irpSp,
                     totalEntries,
-                    &ccb->SearchPattern,
-                    ccb->Flags,
                     returnSingleEntry,
-                    dirInfo,
                     remainingLength,
-                    FillFileIdBothDirInfo,
-                    &used,
-                    &index
+                    indexSpecified,
+                    &index,
+                    &result,
+                    &updateCcb
                 );
-
-                if (NT_SUCCESS(result))
-                {
-                    Request->OriginalIrp->IoStatus.Information = used;
-                }
-
-                updateCcb = !indexSpecified;
                 break;
             }
             case FileDirectoryInformation:
EOF
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bit pedantic - <50 lines on a case statement is fine unless there's obvious easy common logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants