Fixes for various CodeQL findings#676
Draft
uniemimu wants to merge 1 commit into
Draft
Conversation
Plus a regexp cleanup. From copilot autofix. Signed-off-by: Ukri <ukri.niemimuukko@intel.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses several CodeQL findings by tightening integer parsing/conversion semantics and correcting a regexp pattern used when filtering topology hint paths. These changes reduce the risk of unintended truncation/wraparound during numeric parsing and make the regexp match more precise.
Changes:
- Updated sysfs value parsing to parse integers using the target type’s bit size (e.g., int8/int16/uint32) before converting.
- Adjusted global NUMA node ID parsing to use
strconv.Atoiand avoid redundant conversions. - Escaped
.in a regexp sokubernetes.io~...is matched literally.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/sysfs/utils.go | Uses type-sized ParseInt/ParseUint calls to prevent unsafe narrowing conversions when parsing scalar and list integer values. |
| pkg/resmgr/cache/container.go | Fixes regexp to treat kubernetes.io as a literal string in ignored topology path detection. |
| pkg/cgroups/cgroupstats.go | Simplifies NUMA node directory ID parsing and removes an unnecessary cast when indexing the result map. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+196
to
200
| case *uint: | ||
| v, err := strconv.ParseUint(str, 0, 0) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid entry: '%s': %w", str, err) | ||
| } |
Comment on lines
+217
to
+229
| case *uint32: | ||
| v, err := strconv.ParseUint(str, 0, 32) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid entry: '%s': %w", str, err) | ||
| } | ||
| *value = uint32(v) | ||
|
|
||
| case *uint64: | ||
| v, err := strconv.ParseUint(str, 0, 64) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid entry: '%s': %w", str, err) | ||
| } | ||
| *value = v |
Comment on lines
+471
to
474
| node, err := strconv.Atoi(id) | ||
| if err != nil { | ||
| return map[int]GlobalNumaStats{}, fmt.Errorf("error parsing directory name") | ||
| } |
Contributor
Author
|
@kad Please create a PR of your version of the integer conversion fixes. This can be closed then. |
Collaborator
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.
CodeQL findings. Mostly fixes for incorrect conversion between integer types, but includes a regexp cleanup. From copilot autofix.