Skip to content

cache: don't hand-quote cpuset.CPUSet.String()'s. - #775

Open
klihub wants to merge 1 commit into
containers:mainfrom
klihub:fixes/marshal-cpuset-strings
Open

cache: don't hand-quote cpuset.CPUSet.String()'s.#775
klihub wants to merge 1 commit into
containers:mainfrom
klihub:fixes/marshal-cpuset-strings

Conversation

@klihub

@klihub klihub commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

JSON marshal cpuset.CPUSet.String()'s instead of hand-quoting to get rid of a CodeQL alert. Also, do boundary checks on the data before trying to unmarshal.

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.

🟡 Changes recommended

The updated cpuset unmarshaling logic manually strips quotes instead of JSON-decoding the string, which can reject valid JSON inputs (e.g., whitespace/escapes) and is inconsistent with the new marshal behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR hardens and standardizes how cpuset.CPUSet policy entries are encoded/decoded in the resource manager cache, addressing a CodeQL concern and adding input validation before parsing.

Changes:

  • Replace manual quoting of cpuset.CPUSet.String() with json.Marshal(...) for cache storage.
  • Add basic boundary/format checks before attempting to unmarshal cpuset.CPUSet entries.
File summaries
File Description
pkg/resmgr/cache/cache.go Adjusts cpuset policy entry marshaling/unmarshaling behavior and adds validation on input data.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/resmgr/cache/cache.go Outdated
@klihub
klihub force-pushed the fixes/marshal-cpuset-strings branch from ddd8581 to 6576ac7 Compare September 4, 2026 07:02
@klihub
klihub requested a lite review from Copilot September 4, 2026 07:03

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.

🟢 Approval recommended

The changes appear correct and reduce risk (no manual JSON quoting/slicing), with only minor optional improvements noted in review comments.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread pkg/resmgr/cache/cache.go

@askervin askervin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yet there are good chances we'll never see the error from cpuset.Parse(), I still think copilot's suggestion on wrapping it in cacheError is a good idea. It would also be consistent with how cpuset.Parse() error is handled below when unmarshalling into map[string]cpuset.CPUSet.

JSON marshal cpuset.CPUSet.String()'s instead of hand-quoting
to get rid of a CodeQL alert. Also, instead of cpuset.Parsing
data[1:len(data)-1], json.Unmarshal to a string then parse it.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
@klihub
klihub force-pushed the fixes/marshal-cpuset-strings branch from 6576ac7 to 1cd83ba Compare September 5, 2026 07:23
@klihub

klihub commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

Yet there are good chances we'll never see the error from cpuset.Parse(), I still think copilot's suggestion on wrapping it in cacheError is a good idea. It would also be consistent with how cpuset.Parse() error is handled below when unmarshalling into map[string]cpuset.CPUSet.

@askervin True, and it is also then more consistent with any previous string unmarshalling errors. Updated accordingly.

@klihub
klihub requested review from askervin and a lite review from Copilot September 5, 2026 07:24

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.

🟢 Approval recommended

The change is small, localized, and improves correctness/safety of cpuset (un)marshaling without introducing API or behavioral risk.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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