Add NonInheritedFileHandle_IsNotAvailableInChildProcess test to ProcessHandlesTests#126629
Add NonInheritedFileHandle_IsNotAvailableInChildProcess test to ProcessHandlesTests#126629adamsitnik merged 15 commits intomainfrom
Conversation
- Add SystemNative_GetFilePathFromHandle to pal_io.h and pal_io.c: - Linux: readlink /proc/self/fd/<fd> - BSD/macOS: fcntl(fd, F_GETPATH, buf) - Other: errno=ENOTSUP, return -1 - Add HAVE_F_GETPATH cmake check and pal_config.h.in define - Add DllImportEntry for new native function - Add Interop.GetFilePathFromHandle.cs Unix P/Invoke wrapper - Add public Name property to SafeFileHandle.cs - Add GetName() implementations to SafeFileHandle.Unix.cs and SafeFileHandle.Windows.cs - Update OSFileStreamStrategy.Name to use SafeFileHandle.Name - Update System.Runtime ref assembly with new Name property - Add Name tests to GetFileType.cs, GetFileType.Unix.cs, GetFileType.Windows.cs - Add NonInheritedFileHandle_IsNotAvailableInChildProcess test Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/65fff4ad-9081-4ef8-b744-02fef761db67 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetFilePathFromHandle.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetFilePathFromHandle.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
Outdated
Show resolved
Hide resolved
…SafeFileHandle in interop Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/d6f0695b-ba5d-44a8-aa39-c07ea398bcd0 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/d6f0695b-ba5d-44a8-aa39-c07ea398bcd0 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetFilePathFromHandle.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/SafeFileHandle/GetFileType.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/SafeFileHandle/GetFileType.cs
Outdated
Show resolved
Hide resolved
...libraries/System.Runtime/tests/System.IO.FileSystem.Tests/SafeFileHandle/GetFileType.Unix.cs
Outdated
Show resolved
Hide resolved
...raries/System.Runtime/tests/System.IO.FileSystem.Tests/SafeFileHandle/GetFileType.Windows.cs
Outdated
Show resolved
Hide resolved
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/bb17e842-35f7-4bae-8d99-bf98e21541b2 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
Note This review was generated by GitHub Copilot. 🤖 Copilot Code ReviewHolistic AssessmentMotivation: The PR adds a targeted regression test for Approach: Using Summary: Detailed Findings
|
…cess test Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/2da2a1d1-f3e5-43e5-8c03-ac8016a6a5ef Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Note This review was generated by GitHub Copilot (multi-model: Claude Opus 4.6, Gemini 2.5 Pro, GPT-5.4). 🤖 Copilot Code ReviewHolistic AssessmentMotivation: The PR adds a targeted, focused test for Approach: Using platform-specific Summary: Detailed Findings
|
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/2f389c85-bdc5-4872-a751-b96dccc802dc Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.Windows.cs
Show resolved
Hide resolved
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
…to Win32Exception Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8678cac7-b1b2-42ee-ae2b-dde2db2fa421 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Note This review was generated by GitHub Copilot (multi-model: Claude Opus 4.6, Gemini 2.5 Pro, GPT-5.4). 🤖 Copilot Code ReviewHolistic AssessmentMotivation: The PR adds a well-motivated regression test for Approach: The Summary: ✅ LGTM. No blocking correctness issues found across all three models. The findings below are all suggestions/minor notes. Detailed Findings💡 Suggestion — Test method name partially describes the scenario (flagged by 2 models)File:
💡 Suggestion — Windows buffer overflow not fully defended (flagged by 2 models)File:
if (result == 0 || result >= MaxPath)
{
throw new Win32Exception();
}For test code this is extremely low priority (no real path approaches 32,767 chars), but it's a belt-and-suspenders improvement. ✅ Verified —
|
Note This review was generated by GitHub Copilot (multi-model: Gemini 2.5 Pro, GPT-5.4). 🤖 Copilot Code ReviewHolistic AssessmentMotivation: The PR adds a focused, well-motivated test for Approach: The Summary: ✅ LGTM. No blocking correctness issues found across either model. The single finding below is a minor observation, not a blocker. Detailed Findings✅ Test Logic — Correct handle identity comparison
✅ Error Handling — Exception narrowing is correct
💡 Suggestion — Windows buffer size (advisory, test code)
|
Adds a test to
ProcessHandlesTeststhat verifies file handle inheritance behavior when spawning child processes withInheritedHandles. All other changes originally in this PR (native PAL exports,SafeFileHandlepath resolution,GetFileTypetests) have been reverted following reviewer feedback that OS-level path resolution returns device paths rather than the user-friendly paths C# developers expect.Changes
Tests (
System.Diagnostics.Process)ProcessHandlesTests.cs: AddedNonInheritedFileHandle_IsNotAvailableInChildProcessas a[ConditionalTheory]with two scenarios (InlineData(false)andInlineData(true)):false:InheritedHandles = []— verifies the handle is not accessible in the child processtrue:InheritedHandles = [fileHandle]— verifies the handle is accessible and points to the same file in the child processFileShare.Noneso independent opens that honor .NET/OS sharing semantics are preventedGetSafeFileHandleId(a regularprivate staticmethod defined per-platform); identity comparison usesAssert.Equal(shouldBeInherited, childId == fileId)catch (Win32Exception) when (!shouldBeInherited)is used to handle the case where the handle is not valid in the child process —Win32Exceptionis the only exceptionGetSafeFileHandleIdthrows, and it only propagates (failing the test) when the handle was expected to be inheritedGetSafeFileHandleIdcall noting that limiting handle inheritance makes it hard to reliably check whether a handle was not inherited, because the OS can reuse the same handle number for a different pipe/file/device — hence the identity comparison approachProcessHandlesTests.Unix.cs(new): ImplementsGetSafeFileHandleIdasprivate static stringusingInterop.Sys.FStat— returns"{status.Dev}:{status.Ino}"(device + inode, formatted with invariant culture) as the file identity for robustness across different devices/mounts; throwsWin32Exceptionif the syscall failsProcessHandlesTests.Windows.cs: Extended withGetSafeFileHandleIdasprivate static unsafe stringusingInterop.Kernel32.GetFinalPathNameByHandlewith a buffer of 32,767 characters — returns the normalized file path as the file identity; throwsWin32Exceptionon failureSystem.Diagnostics.Process.Tests.csproj: AddedProcessHandlesTests.Unix.csto the Unix item group,Interop.Stat.csfor Unix FStat support, andInterop.GetFinalPathNameByHandle.csfor Windows support