Conversation
76a2ef2 to
e0cb46b
Compare
c1764fe to
0013783
Compare
467da90 to
3cd88ad
Compare
0afd57f to
219a440
Compare
219a440 to
2209123
Compare
| 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
Show autofix suggestion
Hide autofix suggestion
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.
There was a problem hiding this comment.
bit pedantic - <50 lines on a case statement is fine unless there's obvious easy common logic
No description provided.