IIS/ANCM: UNC `stdoutLogFile` causes invalid directory creation (ERROR_BAD_PATHNAME)
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
When `stdoutLogFile` is set to a UNC path (e.g. `\\SERVER\path\stdout.log`), ANCM canonicalizes the path to the extended `\?\UNC\SERVER\path\stdout.log_...` form and then attempts to create path segments starting at the wrong offset. This leads to an attempt to create the server-only path (`\?\UNC\SERVER`) which fails with `ERROR_BAD_PATHNAME` (0x800700A1) and prevents the log file from being created.
### Expected Behavior
The log file should have been created properly.
### Steps To Reproduce
1. Configure an ASP.NET Core app hosted by IIS/ANCM with `stdoutLogEnabled="true"`.
2. Set `stdoutLogFile` to a UNC path, for example:
```xml
```
3. Start the site (IIS) and observe the Windows Event Log for ANCM errors.
Event log contains an error similar to:
`Could not create stdoutLogFile \?\UNC\SERVER\path\stdout.log_..., ErrorCode = '0x800700a1'`
- The failure occurs during `EnsureDirectoryPathExists` (before `CreateFileW`) when `CreateDirectory` is called for `\?\UNC\SERVER`.
### Exceptions (if any)
_No response_
### .NET Version
v10.0.4 but it also applies to other versions and main HEAD
### Anything else?
Affected code: `src/Servers/IIS/AspNetCoreModuleV2/CommonLib/file_utility.cpp` (`FILE_UTILITY::EnsureDirectoryPathExists`) and `IISLib::MakePathCanonicalizationProof`.
Originally reported to HTTP Bridge module for IIS as https://github.com/lextudio/httpbridge/issues/9
Contributor guide
Assessment
This issue has not been assessed yet.