Skip to content

fix gosec g602 error for make validate-all#911

Merged
doringeman merged 3 commits into
docker:mainfrom
areebahmeddd:fix/false-lint
May 13, 2026
Merged

fix gosec g602 error for make validate-all#911
doringeman merged 3 commits into
docker:mainfrom
areebahmeddd:fix/false-lint

Conversation

@areebahmeddd
Copy link
Copy Markdown
Contributor

closes #906

Signed-off-by: Areeb Ahmed <areebahmed0709@gmail.com>
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In TestBracketWriter_MultipleLines, iterating over expected and indexing into lines assumes both slices have the same length and can panic; consider asserting the lengths match up front or iterating safely over the shorter slice to make the test more robust to unexpected output.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `TestBracketWriter_MultipleLines`, iterating over `expected` and indexing into `lines` assumes both slices have the same length and can panic; consider asserting the lengths match up front or iterating safely over the shorter slice to make the test more robust to unexpected output.

## Individual Comments

### Comment 1
<location path="pkg/logging/bracket_writer_test.go" line_range="56-60" />
<code_context>
 	expected := []string{"line one", "line two", "line three"}
-	for i, line := range lines {
-		matches := timestampRe.FindStringSubmatch(line)
+	for i, want := range expected {
+		matches := timestampRe.FindStringSubmatch(lines[i])
 		if len(matches) != 3 {
-			t.Errorf("line %d did not match format: %q", i, line)
-			continue
-		}
-		if matches[2] != expected[i] {
-			t.Errorf("line %d: expected %q, got %q", i, expected[i], matches[2])
+			t.Errorf("line %d did not match format: %q", i, lines[i])
+		} else if matches[2] != want {
+			t.Errorf("line %d: expected %q, got %q", i, want, matches[2])
 		}
</code_context>
<issue_to_address>
**issue:** Guard against potential index-out-of-range panic when indexing lines by i

Indexing lines[i] while ranging over expected will panic if the implementation returns fewer lines than expected, giving a runtime error instead of a clear assertion about the mismatch in lengths. Please add an explicit length check (e.g., len(lines) == len(expected) or at least len(lines) >= len(expected)) before the loop, or restore iteration over lines and assert the line count first so the test fails with a clear message instead of panicking.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread pkg/logging/bracket_writer_test.go
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Makefile to include the Go binary path in the environment and refactors a logging test for improved clarity. A critical issue was identified in the Makefile where the PATH export fails if GOPATH contains multiple entries, potentially leading to environment misconfiguration or security risks.

Comment thread Makefile Outdated
Comment thread Makefile Outdated
@doringeman doringeman merged commit 8671464 into docker:main May 13, 2026
8 checks passed
@areebahmeddd areebahmeddd deleted the fix/false-lint branch May 13, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

false lint issue blocking checks

4 participants