Skip to content

Return error if no overlay mount found for pid#771

Open
matthyx wants to merge 1 commit intomainfrom
fix/sbom-panic
Open

Return error if no overlay mount found for pid#771
matthyx wants to merge 1 commit intomainfrom
fix/sbom-panic

Conversation

@matthyx
Copy link
Copy Markdown
Contributor

@matthyx matthyx commented Apr 3, 2026

Prevents this panic:

panic: runtime error: index out of range [0] with length 0

goroutine 119 [running]:
github.com/kubescape/node-agent/pkg/sbommanager/v1.(*SbomManager).getMountedVolumes(0xc00104aa88, {0xc001ece0d8, 0x7})
	/work/pkg/sbommanager/v1/sbom_manager.go:136 +0x6a5
github.com/kubescape/node-agent/pkg/sbommanager/v1.(*SbomManager).ContainerCallback(0xc00104aa88, {{0xc001e99020?, 0x281fe200000004?}, 0x200000000000030?, 0xc000c986c8?})
	/work/pkg/sbommanager/v1/sbom_manager.go:163 +0xa7
github.com/kubescape/node-agent/pkg/containerwatcher/v2.(*ContainerWatcher).containerCallback.func1()
	/work/pkg/containerwatcher/v2/containercallback.go:45 +0x27
github.com/kubescape/workerpool.worker.func1(...)
	/go/pkg/mod/github.com/kubescape/workerpool@v0.0.0-20250526074519-0e4a4e7f44cf/workerpool.go:252
created by github.com/kubescape/workerpool.worker in goroutine 102
	/go/pkg/mod/github.com/kubescape/workerpool@v0.0.0-20250526074519-0e4a4e7f44cf/workerpool.go:251 +0x13f

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling in the SBOM manager to prevent crashes when processing system mounts, now returning a clear error message instead of failing unexpectedly.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5ab86712-7320-4952-9eda-69fb9cf5f7cc

📥 Commits

Reviewing files that changed from the base of the PR and between 9a09420 and 135575a.

📒 Files selected for processing (1)
  • pkg/sbommanager/v1/sbom_manager.go

📝 Walkthrough

Walkthrough

The getMountedVolumes function was enhanced with an explicit error check to validate that the filtered overlay mounts list contains entries before attempting to access the first element, preventing potential index-out-of-bounds errors.

Changes

Cohort / File(s) Summary
Error handling for empty mounts
pkg/sbommanager/v1/sbom_manager.go
Added guard clause to return error when no overlay mounts are found after filtering, instead of proceeding to access mounts[0] unsafely.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A guard clause hops into view,
Checking mounts before we pursue,
No more panics when lists are bare,
Safety now floats through the air! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Return error if no overlay mount found for pid' directly summarizes the main change: adding error handling for the case when no overlay mount is found, preventing an index-out-of-range panic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sbom-panic

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
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.

2 participants