fix: filter out non-printable characters in process line

Otherwise the output might be distorted by characters like `\n`.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
(cherry picked from commit 8166a58b364f760212b2a610ce0d764b8b4c5c46)
This commit is contained in:
Andrey Smirnov 2024-09-19 21:19:43 +04:00
parent 70d3c91fb7
commit c8dedbe116
No known key found for this signature in database
GPG Key ID: FE042E3D4085A811
2 changed files with 21 additions and 0 deletions

View File

@ -178,6 +178,7 @@ var cpu = func(p1, p2 *machineapi.ProcessInfo) bool {
return p1.CpuTime > p2.CpuTime
}
//nolint:gocyclo
func processesOutput(ctx context.Context, c *client.Client) (output string, err error) {
var remotePeer peer.Peer
@ -214,6 +215,15 @@ func processesOutput(ctx context.Context, c *client.Client) (output string, err
args = p.Args
}
// filter out non-printable characters
args = strings.Map(func(r rune) rune {
if r < 32 || r > 126 {
return ' '
}
return r
}, args)
node := defaultNode
if msg.Metadata != nil {

View File

@ -50,6 +50,8 @@ func NewProcessTable() *ProcessTable {
}
// OnAPIDataChange implements the APIDataListener interface.
//
//nolint:gocyclo
func (widget *ProcessTable) OnAPIDataChange(node string, data *apidata.Data) {
nodeData := data.Nodes[node]
@ -97,6 +99,15 @@ func (widget *ProcessTable) OnAPIDataChange(node string, data *apidata.Data) {
args = proc.Args
}
// filter out non-printable characters
args = strings.Map(func(r rune) rune {
if r < 32 || r > 126 {
return ' '
}
return r
}, args)
line := fmt.Sprintf("%7d %s %6.1f %6.1f %8s %8s %10s %4d %s",
proc.GetPid(),
proc.State,