Conversation
486a744 to
4e9a8de
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses golangci-lint (gosec/perfsprint) findings by adding targeted suppressions for gosec warnings around dynamic file paths and subprocess execution, and by refactoring a warning formatter to avoid fmt.Sprintf-in-loop patterns.
Changes:
- Add
//nolint:gosecsuppressions for dynamicexec.CommandContextusage in process tests. - Add
//nolint:gosecsuppressions foros.Statcalls on constructed proc/sys paths. - Replace
sb.WriteString(fmt.Sprintf(...))withfmt.Fprintf(&sb, ...)in warning formatting.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| process/process_test.go | Adds per-line gosec suppressions for dynamic exec.CommandContext invocations in tests. |
| process/process_posix.go | Suppresses gosec warning for os.Stat on /proc/<pid> path built via host override helper. |
| internal/common/warnings.go | Refactors string building to avoid Sprintf+WriteString in a loop (perfsprint). |
| internal/common/common.go | Suppresses gosec warnings for variable-path os.Stat within PathExists* helpers. |
Comments suppressed due to low confidence (6)
internal/common/common.go:330
//nolint:goseconos.Stat(filename)insidePathExistssuppresses G304 for all callers of this helper. Sincefilenamecan be derived from environment-based host path overrides (HOST_*) and from exported APIs that accept string inputs (e.g. callers building sysfs/procfs paths), this blanket suppression can hide real file-inclusion/path-traversal findings. Prefer keepingPathExistsclean and placing a narrowly-scoped suppression at the specific safe call sites, or add validation that the path stays within an expected base directory; also adjust the comment text since “not user input” isn’t guaranteed here.
if _, err := os.Stat(filename); err == nil {
return true
internal/common/common.go:338
- Same concern as
PathExists: suppressing gosec at the helper level (os.Stat(filename)) makes future unsafe call sites invisible to the linter. Consider moving the suppression to the specific call sites that are known-safe, or validating/sanitizingfilenamebefore stat’ing it; the current comment claims it’s not user input, which isn’t universally true for this helper.
info, err := os.Stat(filename) //nolint:gosec // filename is constructed from system paths, not user input
if err != nil {
process/process_posix.go:114
- The
//nolint:gosecjustification here focuses onpidbeing anint32, but the path being stat’d also depends oncommon.HostProcWithContext(ctx)(which is derived from env/context overrides). If this is suppressing G304, please update the rationale to reflect the actual trust boundary (HOST_PROC overrides) and consider constraining/validating the constructed path (or scoping the suppression as tightly as possible).
_, err := os.Stat(common.HostProcWithContext(ctx, strconv.Itoa(int(pid)))) //nolint:gosec // pid is int32, path traversal is not possible
process/process_test.go:289
- This test already has a
// #nosec G204marker above the function, and now also uses per-line//nolint:gosecdirectives. To reduce confusion and avoid future lint churn, consider using a single suppression style consistently (e.g., keep only the per-line suppression on the specificexec.CommandContextcalls that trigger gosec, and remove/relocate the function-level#nosecif it’s not needed).
err = exec.CommandContext(ctx, "go", "build", "-o", tmpfile.Name()+".exe", tmpfile.Name()).Run() //nolint:gosec // test code
require.NoErrorf(t, err, "unable to build temp file %v", err)
cmd := exec.CommandContext(ctx, tmpfile.Name()+".exe") //nolint:gosec // test code
process/process_test.go:329
- Same as above: there are both function-level
// #nosec G204comments and per-line//nolint:gosecdirectives in this test. Consider consolidating to one mechanism (preferably per-line on the exactexec.CommandContextcalls) so it’s clear what is being suppressed and why.
err = exec.CommandContext(ctx, "go", "build", "-o", tmpfile.Name()+".exe", tmpfile.Name()).Run() //nolint:gosec // test code
require.NoErrorf(t, err, "unable to build temp file %v", err)
cmd := exec.CommandContext(ctx, tmpfile.Name()+".exe") //nolint:gosec // test code
process/process_test.go:717
- Same as above: consider consolidating gosec suppression directives (function-level
#nosecvs per-line//nolint:gosec) to a single, clearly scoped approach to keep the test’s intent and linting behavior easy to understand.
err = exec.CommandContext(ctx, "go", "build", "-o", tmpfile.Name()+".exe", tmpfile.Name()).Run() //nolint:gosec // test code
require.NoErrorf(t, err, "unable to build temp file %v", err)
cmd := exec.CommandContext(ctx, tmpfile.Name()+".exe") //nolint:gosec // test code
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix gosec lint (ref). We can ignore all of the warnings.