From c8dedbe1161d1ebfc8325c734357dc64f049f118 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 19 Sep 2024 21:19:43 +0400 Subject: [PATCH] fix: filter out non-printable characters in process line Otherwise the output might be distorted by characters like `\n`. Signed-off-by: Andrey Smirnov (cherry picked from commit 8166a58b364f760212b2a610ce0d764b8b4c5c46) --- cmd/talosctl/cmd/talos/processes.go | 10 ++++++++++ internal/pkg/dashboard/components/tables.go | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/cmd/talosctl/cmd/talos/processes.go b/cmd/talosctl/cmd/talos/processes.go index 293dadb2fa..70c182f10f 100644 --- a/cmd/talosctl/cmd/talos/processes.go +++ b/cmd/talosctl/cmd/talos/processes.go @@ -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 { diff --git a/internal/pkg/dashboard/components/tables.go b/internal/pkg/dashboard/components/tables.go index e57bdae0e4..da083da47d 100644 --- a/internal/pkg/dashboard/components/tables.go +++ b/internal/pkg/dashboard/components/tables.go @@ -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,