Fix to properly handle EOL chars in the Get-Process CommandLine prope…#27501
Open
kevin-hoffman wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds Linux-focused coverage for Get-Process.CommandLine when the command line contains embedded newline characters, and adjusts Linux command line extraction to return a single string instead of an array.
Changes:
- Added Pester tests to validate
CommandLinetype (String) and behavior when the command line contains a newline. - Updated Linux
CommandLinegeneration to useGet-Content -Rawfor/proc/<pid>/cmdlineso the result stays a single string.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 | Adds Linux-only tests for embedded newline behavior and type consistency of CommandLine. |
| src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs | Updates Linux process command line reading to use -Raw to avoid Object[] output. |
Comments suppressed due to low confidence (1)
src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs:1
- With
-Raw,$rawCmdwill be an empty string when/proc/<pid>/cmdlineis empty (common for some kernel threads / certain processes). In that case,$rawCmd.Length - 1becomes-1andSubstring(0, -1)will throw. Prefer trimming the trailing null safely (e.g.,TrimEnd([char]0)), or only applyingSubstringwhen$rawCmd.Length -gt 0and the last character is0.
// Copyright (c) Microsoft Corporation.
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Fixes an issue with the Get-Process CommandLine property where it gets truncated if a newline character is embedded in the command line being parsed.
PR Context
Fixes #27499
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header