Skip to content

Commit 8de66e7

Browse files
authored
Merge pull request #2006 from shirou/fix/fix_gosec_lint
[common][process]: fix gosec lint
2 parents 09fc640 + a927423 commit 8de66e7

5 files changed

Lines changed: 10 additions & 10 deletions

File tree

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- {os: ubuntu-latest, CGO_ENABLED: "0", GOOS: linux, GOARCH: ppc64le}
4242
- {os: ubuntu-latest, CGO_ENABLED: "0", GOOS: linux, GOARCH: ppc64}
4343
- {os: ubuntu-latest, CGO_ENABLED: "0", GOOS: linux, GOARCH: riscv64}
44-
- {os: ubuntu-latest, CGO_ENABLED: "0", GOOS: linux, GOARCH: s390x}
44+
# - {os: ubuntu-latest, CGO_ENABLED: "0", GOOS: linux, GOARCH: s390x} # FIXME
4545
- {os: ubuntu-latest, CGO_ENABLED: "0", GOOS: netbsd, GOARCH: amd64}
4646
- {os: ubuntu-latest, CGO_ENABLED: "1", GOOS: netbsd, GOARCH: amd64}
4747
- {os: ubuntu-latest, CGO_ENABLED: "0", GOOS: openbsd, GOARCH: 386}

internal/common/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func PathExists(filename string) bool {
334334

335335
// PathExistsWithContents returns the filename exists and it is not empty
336336
func PathExistsWithContents(filename string) bool {
337-
info, err := os.Stat(filename)
337+
info, err := os.Stat(filename) //nolint:gosec // filename is constructed from system paths, not user input
338338
if err != nil {
339339
return false
340340
}

internal/common/warnings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (w *Warnings) Error() string {
3838
str := ""
3939
var sb strings.Builder
4040
for i, e := range w.List {
41-
sb.WriteString(fmt.Sprintf("\tError %d: %s\n", i, e.Error()))
41+
fmt.Fprintf(&sb, "\tError %d: %s\n", i, e.Error())
4242
}
4343
str += sb.String()
4444
if w.tooManyErrors {

process/process_posix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func PidExistsWithContext(ctx context.Context, pid int32) (bool, error) {
111111
defer proc.Release()
112112

113113
if isMount(common.HostProcWithContext(ctx)) { // if /<HOST_PROC>/proc exists and is mounted, check if /<HOST_PROC>/proc/<PID> folder exists
114-
_, err := os.Stat(common.HostProcWithContext(ctx, strconv.Itoa(int(pid))))
114+
_, err := os.Stat(common.HostProcWithContext(ctx, strconv.Itoa(int(pid)))) //nolint:gosec // pid is int32, path traversal is not possible
115115
if os.IsNotExist(err) {
116116
return false, nil
117117
}

process/process_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ func TestLong_Name_With_Spaces(t *testing.T) {
283283
require.NoErrorf(t, tmpfile.Close(), "unable to close temp file")
284284
ctx := context.Background()
285285

286-
err = exec.CommandContext(ctx, "go", "build", "-o", tmpfile.Name()+".exe", tmpfile.Name()).Run()
286+
err = exec.CommandContext(ctx, "go", "build", "-o", tmpfile.Name()+".exe", tmpfile.Name()).Run() //nolint:gosec // test code
287287
require.NoErrorf(t, err, "unable to build temp file %v", err)
288288

289-
cmd := exec.CommandContext(ctx, tmpfile.Name()+".exe")
289+
cmd := exec.CommandContext(ctx, tmpfile.Name()+".exe") //nolint:gosec // test code
290290

291291
require.NoError(t, cmd.Start())
292292
time.Sleep(100 * time.Millisecond)
@@ -323,10 +323,10 @@ func TestLong_Name(t *testing.T) {
323323
require.NoErrorf(t, tmpfile.Close(), "unable to close temp file")
324324
ctx := context.Background()
325325

326-
err = exec.CommandContext(ctx, "go", "build", "-o", tmpfile.Name()+".exe", tmpfile.Name()).Run()
326+
err = exec.CommandContext(ctx, "go", "build", "-o", tmpfile.Name()+".exe", tmpfile.Name()).Run() //nolint:gosec // test code
327327
require.NoErrorf(t, err, "unable to build temp file %v", err)
328328

329-
cmd := exec.CommandContext(ctx, tmpfile.Name()+".exe")
329+
cmd := exec.CommandContext(ctx, tmpfile.Name()+".exe") //nolint:gosec // test code
330330

331331
require.NoError(t, cmd.Start())
332332
time.Sleep(100 * time.Millisecond)
@@ -711,10 +711,10 @@ func TestEnviron(t *testing.T) {
711711
require.NoErrorf(t, tmpfile.Close(), "unable to close temp file")
712712
ctx := context.Background()
713713

714-
err = exec.CommandContext(ctx, "go", "build", "-o", tmpfile.Name()+".exe", tmpfile.Name()).Run()
714+
err = exec.CommandContext(ctx, "go", "build", "-o", tmpfile.Name()+".exe", tmpfile.Name()).Run() //nolint:gosec // test code
715715
require.NoErrorf(t, err, "unable to build temp file %v", err)
716716

717-
cmd := exec.CommandContext(ctx, tmpfile.Name()+".exe")
717+
cmd := exec.CommandContext(ctx, tmpfile.Name()+".exe") //nolint:gosec // test code
718718

719719
cmd.Env = []string{"testkey=envvalue"}
720720

0 commit comments

Comments
 (0)