Potential fix for code scanning alert no. 50: Incorrect conversion between integer types#783
Merged
Potential fix for code scanning alert no. 50: Incorrect conversion between integer types#783
Conversation
…tween integer types Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #783 +/- ##
==========================================
- Coverage 70.93% 70.89% -0.04%
==========================================
Files 457 457
Lines 41302 41302
==========================================
- Hits 29297 29283 -14
- Misses 9844 9857 +13
- Partials 2161 2162 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Potential fix for https://github.com/marle3003/mokapi/security/code-scanning/50
We should guarantee that only values that fit within the int16 type are assigned to the struct field
t.nullable. There are two idiomatic ways to do this in Go:strconv.ParseInt(kv[1], 10, 16), then assign after checking error, orstrconv.Atoi, but add explicit bounds checks againstmath.MinInt16andmath.MaxInt16before assignment.Option 1 is the cleanest and most direct fix; it eliminates the risk of
intbeing a wider type and avoids needing bounds checks. The code should extract the integer value as an int64, check for error, and then assign as int16.Therefore, in
kafka/protocol.go, lines 193–194 should be replaced so that instead of usingstrconv.Atoi(kv[1]), we usestrconv.ParseInt(kv[1], 10, 16); on success, assign asint16(parsed). This preserves the code's logic and safety.No new imports are required (strconv is already used).
Suggested fixes powered by Copilot Autofix. Review carefully before merging.