Skip to content

Commit

Permalink
chore: fix gosec G304 lint issue
Browse files Browse the repository at this point in the history
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
  • Loading branch information
Juneezee authored and ciarams87 committed Feb 7, 2022
1 parent 8504d46 commit 12854a1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/metrics/collectors/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"bytes"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -56,7 +58,10 @@ func getWorkerProcesses() (int, int, error) {
continue
}

cmdlineFile := fmt.Sprintf("/proc/%v/cmdline", folder.Name())
cmdlineFile := filepath.Clean(fmt.Sprintf("/proc/%v/cmdline", folder.Name()))
if !strings.HasPrefix(cmdlineFile, "/proc/") {
panic(fmt.Errorf("unsafe input"))
}
content, err := os.ReadFile(cmdlineFile)
if err != nil {
return 0, 0, fmt.Errorf("unable to read file %v: %w", cmdlineFile, err)
Expand Down

0 comments on commit 12854a1

Please sign in to comment.