Fix Incorrect conversion between integer types #9661
+4
−0
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.
To address the incorrect conversion, we should ensure that only valid, positive, in-range user and group IDs are allowed to flow to the place they are cast to
uint32
. The best fix is to add explicit range checks where the conversion from int (parsed from string) to the UID/GID storage location happens—specifically in the return statements ofgetentGetID
,FindUID
, andFindGID
ininternal/pkg/agent/install/user_linux.go
. These must only return an id if it is within[0, math.MaxUint32]
, otherwise return an error. This prevents any "out of range" id from ever being used to populate theownership
struct or to reach the cast in the credential setup.To implement this:
internal/pkg/agent/install/user_linux.go
:getentGetID
, after parsing the id, check that 0 <= val <= math.MaxUint32. If not, return error."math"
formath.MaxUint32
.This patch does not change the user-facing functionality; it only ensures that the code safely handles ids from the OS and will fail fast if there are anomalies.
References
Integer overflow
Go language specification Integer overflow
strconv.Atoi
strconv.ParseInt
strconv.ParseUint
Checklist
./changelog/fragments
using the changelog tool