Skip to content

[scanner] fix: safe uintptr-to-int conversion in flock_unix.go#19787

Merged
clubanderson merged 7 commits into
mainfrom
scanner/fix-19782
Jun 27, 2026
Merged

[scanner] fix: safe uintptr-to-int conversion in flock_unix.go#19787
clubanderson merged 7 commits into
mainfrom
scanner/fix-19782

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Fixes #19782

Fixes gosec G115 integer overflow finding in pkg/agent/tokentracker/flock_unix.go by adding bounds checking for the uintptr-to-int conversion. The fix validates that the file descriptor value fits within the int range before conversion, preventing potential integer overflow on systems where uintptr is larger than int.

Fixes #19782

Adds bounds checking for the uintptr to int conversion to prevent
integer overflow (gosec G115). File descriptors are validated to fit
within the int range before conversion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 27, 2026 09:07
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: no Indicates the PR's author has not signed the DCO. label Jun 27, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mikespreitzer for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify

netlify Bot commented Jun 27, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit 13c8c78
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a3fcbc0a67ffc000832446e

@github-actions

Copy link
Copy Markdown
Contributor

🐝 Hi @clubanderson! I'm kubestellar-hive[bot], an automation bot for this repo.

Trusted users — org members and contributors with write access — can mention @kubestellar-hive in a comment to trigger repo automation.
On issues, that mention queues an automated fix attempt. On pull requests, it records extra context for existing automation.
This is not an interactive Q&A bot, so mentions should be treated as requests for automation rather than a conversation.

Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies.

@github-actions github-actions Bot added the ai-generated Pull request generated by AI label Jun 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Addresses the gosec G115 finding in the token tracker’s Unix file-lock implementation by ensuring the uintptr file descriptor returned by (*os.File).Fd() is validated before converting to int.

Changes:

  • Added a bounds check to ensure f.Fd() fits in int prior to conversion (prevents potential overflow on platforms where uintptr is wider than int).
  • Introduced math.MaxInt usage to express the upper bound clearly.
Comments suppressed due to low confidence (1)

pkg/agent/tokentracker/flock_unix.go:38

  • Consider explicitly discarding the Close() error (_ = f.Close()) for consistency with the release() closure and to avoid linters flagging an ignored return value.
	if err := syscall.Flock(fd, syscall.LOCK_EX); err != nil {
		f.Close()
		return nil, fmt.Errorf("flock: %w", err)

Comment on lines +30 to +33
if uintptrVal > uintptr(math.MaxInt) {
f.Close()
return nil, fmt.Errorf("file descriptor out of range: %v", uintptrVal)
}
// Safe conversion: validate uintptr fits in int (gosec G115)
uintptrVal := f.Fd()
if uintptrVal > uintptr(math.MaxInt) {
f.Close()
Signed-off-by: clubanderson <clubanderson@users.noreply.github.com>
After merging main, line numbers shifted in cluster_groups_test.go
and solver.go. Update baseline entries to match current positions.

Signed-off-by: clubanderson <clubanderson@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 27, 2026
Signed-off-by: clubanderson <clubanderson@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 27, 2026
clubanderson and others added 2 commits June 27, 2026 08:08
Signed-off-by: clubanderson <clubanderson@users.noreply.github.com>
@kubestellar-prow

Copy link
Copy Markdown
Contributor

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

  • 534b7fb [scanner] fix: safe uintptr-to-int conversion in flock_unix.go
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@clubanderson clubanderson merged commit 9891058 into main Jun 27, 2026
28 of 31 checks passed
@kubestellar-prow kubestellar-prow Bot deleted the scanner/fix-19782 branch June 27, 2026 13:37
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

@github-actions

Copy link
Copy Markdown
Contributor

✅ Post-Merge Verification: passed

Commit: 989105895bf75c34f4b7968835fc3eb20fa58d9a
Specs run: smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/28290828526

@github-actions

Copy link
Copy Markdown
Contributor

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit 989105895bf75c34f4b7968835fc3eb20fa58d9a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Pull request generated by AI dco-signoff: no Indicates the PR's author has not signed the DCO. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tier/2-standard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nightly regression: gosec-test

2 participants