From 81574a5c8df7e15fd045710a97d1b5d0ebec8e23 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 15 Sep 2022 12:17:31 +0200 Subject: [PATCH] portlist: normalise space delimited process names (#5634) --- portlist/clean.go | 3 +++ portlist/clean_test.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/portlist/clean.go b/portlist/clean.go index aad350fe3..9473c39e2 100644 --- a/portlist/clean.go +++ b/portlist/clean.go @@ -26,6 +26,9 @@ func argvSubject(argv ...string) string { ret = filepath.Base(argv[1]) } + // Handle space separated argv + ret, _, _ = strings.Cut(ret, " ") + // Remove common noise. ret = strings.TrimSpace(ret) ret = strings.TrimSuffix(ret, ".exe") diff --git a/portlist/clean_test.go b/portlist/clean_test.go index 767071481..2778d249f 100644 --- a/portlist/clean_test.go +++ b/portlist/clean_test.go @@ -31,6 +31,22 @@ func TestArgvSubject(t *testing.T) { in: []string{"/bin/mono", "/sbin/exampleProgram.bin"}, want: "exampleProgram.bin", }, + { + in: []string{"/usr/bin/sshd_config [listener] 1 of 10-100 startups"}, + want: "sshd_config", + }, + { + in: []string{"/usr/bin/sshd [listener] 0 of 10-100 startups"}, + want: "sshd", + }, + { + in: []string{"/opt/aws/bin/eic_run_authorized_keys %u %f -o AuthorizedKeysCommandUser ec2-instance-connect [listener] 0 of 10-100 startups"}, + want: "eic_run_authorized_keys", + }, + { + in: []string{"/usr/bin/nginx worker"}, + want: "nginx", + }, } for _, test := range tests {