fix(pilotctl): bounds-check --net before uint16 truncation (CodeQL #21,#23,#24,#25,#32)#218
Merged
Conversation
…#23,#24,#25,#32) flagInt returns an int; `uint16(flagInt(...))` silently truncates when the user passes a value > 65535. `--net 70000` becomes uint16(70000 & 0xFFFF)=4464, so the command operates on the wrong network without warning. Introduce flagNetID helper that bounds-checks and aborts on out-of-range input, then replace all 5 truncation call sites.
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.
Summary
Closes 5 CodeQL "Incorrect conversion between integer types" alerts by introducing
flagNetID— a helper that validates--net Nis in0..65535before castingint → uint16, rather than silently truncating.Before:
--net 70000→uint16(70000 & 0xFFFF) = 4464— command runs against the wrong network with no warning.After:
--net 70000→ fatalinvalid_argument: --net must be in 0..65535, got 70000.Closes
Not addressed in this PR
workflowOAuth scope. The required changes (addpermissions: contents: readat the workflow root level ofcodeql.ymlandnotify-canary.yml) are trivial — refresh your gh token withgh auth refresh -s workflowand either commit them directly or ping me to push.Test plan
go build ./cmd/pilotctl/...succeedspilotctl network info --net 70000now aborts instead of silently picking net 4464--net 1/--net 100flows unchanged