Skip to content

Conversation

@hairyhenderson
Copy link
Contributor

Fixes the issue I recently found in #1212 (comment).

When converting to an int* from a uint64 created by strconv.ParseUint with a specified bit size less than the size of the destination integer, currently G115 is falsely triggered.

That's because the current check only allows the source and destination sign to match (i.e. from int* to int* or uint* to uint*). This is a useful check when going from ParseInt to a uint*, but when going from ParseUint to an int* the conversion is safe as long as the bit size is at least one less.

I've added the extra test and documented it since the logic is somewhat complex.

I've also added a few test cases to catch regressions.

Signed-off-by: Dave Henderson <dhenderson@gmail.com>
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.71%. Comparing base (1216c9b) to head (78e7ae6).
Report is 9 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1254      +/-   ##
==========================================
- Coverage   68.49%   66.71%   -1.79%     
==========================================
  Files          75       75              
  Lines        4384     5195     +811     
==========================================
+ Hits         3003     3466     +463     
- Misses       1233     1581     +348     
  Partials      148      148              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ccojocar ccojocar merged commit 9b13cd5 into securego:master Nov 26, 2024
6 checks passed
@hairyhenderson hairyhenderson deleted the fix-false-g115-positive-casting-to-int-1212 branch November 26, 2024 14:50
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