Skip to content

Directory traversal/output bugs in DosBatchRoutingIntegrationTests #2148

@assumenothing

Description

@assumenothing

Describe the bug
There are several tests in the class DosBatchRoutingIntegrationTests which test for the output files in the wrong directories.

  1. HostRequestedBatch_Cd_ChangesDirectory_ThenPrintsNew() - The batch file should write "OUT.TXT" into DOS-mapped folder "C:\SUBDIR\OUT.TXT". Test currently assumes root of drive.
  2. HostRequestedBatch_CdDot_StaysInCurrentDirectory() - The batch file should write "OUT.TXT" into DOS-mapped folder "C:\SUB\OUT.TXT". Test currently assumes root of drive.
  3. HostRequestedBatch_Md_CreatesDirectory() - The batch file should write "OUT.TXT" into DOS-mapped folder "C:\NEWDIR\OUT.TXT". Test currently assumes root of drive.
  4. HostRequestedBatch_Mkdir_IsAliasForMd() - The batch file should write "OUT.TXT" into DOS-mapped folder "C:\SUBDIR\OUT.TXT". Test currently assumes root of drive.

To Reproduce
Run unit tests for "DosBatchRoutingIntegrationTests". The tests should fail in their current form.

Expected behavior
The tests should not be passing in their current form. If the unit tests are currently passing, then there are likely problems with the way that file paths are being resolved in the batch files or other DOS filesystem APIs.

Test system

  • OS: Windows 11 version 25H2
  • .NET 10 Installed Runtimes: Microsoft.AspNetCore.App 10.0.7, Microsoft.NETCore.App 10.0.7, Microsoft.WindowsDesktop.App 10.0.7
  • .NET 10 Installed SDK Version: 10.0.203

Additional context
I found this while experimenting with changes to various internal file system and drive-related APIs. I had patched a number of methods inside DosPathResolver, including a full rewrite of the GetFullDosPathIncludingRoot method--which you currently are using a bad path traversal algorithm.

I likely found/fixed the bug while I was messing around with rewriting DosDriveManager. Though at the time when I made these local source changes (this last weekend), I didn't realize that there is currently heavy development inside those APIs right now.

There are currently two possible fixes that I can see for these tests to be correct:

  1. Modify the batch scripts in the tests to use > \OUT.TXT so "OUT.TXT" is always located at the root of the current drive specified.
  2. Modify the tests so they reference the proper directories where "OUT.TXT" is being written (by adding the required sub-directories to the Path.Join calls.

Metadata

Metadata

Assignees

Labels

DOSRelated to DOSbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions