Skip to content

Fixes for various CodeQL findings#676

Draft
uniemimu wants to merge 1 commit into
containers:mainfrom
uniemimu:codeqlfixes
Draft

Fixes for various CodeQL findings#676
uniemimu wants to merge 1 commit into
containers:mainfrom
uniemimu:codeqlfixes

Conversation

@uniemimu

Copy link
Copy Markdown
Contributor

CodeQL findings. Mostly fixes for incorrect conversion between integer types, but includes a regexp cleanup. From copilot autofix.

Plus a regexp cleanup. From copilot autofix.

Signed-off-by: Ukri <ukri.niemimuukko@intel.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.Atoi and avoid redundant conversions.
  • Escaped . in a regexp so kubernetes.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 thread pkg/sysfs/utils.go
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 thread pkg/sysfs/utils.go
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")
}
@uniemimu uniemimu marked this pull request as draft June 11, 2026 15:59
@uniemimu

Copy link
Copy Markdown
Contributor Author

@kad Please create a PR of your version of the integer conversion fixes. This can be closed then.

@kad

kad commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

@kad Please create a PR of your version of the integer conversion fixes. This can be closed then.

#682 has my changes, including testcases for changed functions.

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.

3 participants