Conversation
| } | ||
|
|
||
| readReq := &cxsdk.GetViewRequest{ | ||
| Id: wrapperspb.Int32(int32(id)), |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix this issue, we should add explicit upper and lower bounds checking before casting from int (returned from strconv.Atoi) to int32. If the parsed value falls outside the legal range for int32 (i.e., less than math.MinInt32 or greater than math.MaxInt32), we should return an appropriate error to the caller.
The best solution is to:
- Import the
mathpackage if not already present. - After parsing the integer, check
id < math.MinInt32orid > math.MaxInt32. - If outside the range, add an error to the diagnostics and return.
- Only do the cast to
int32if the bounds check passes.
All this needs to be done in internal/provider/data_exploration/resource_coralogix_view.go at/after lines 660-670.
Suggested changeset
1
internal/provider/data_exploration/resource_coralogix_view.go
| @@ -18,6 +18,7 @@ | ||
| "context" | ||
| "fmt" | ||
| "log" | ||
| "math" | ||
| "regexp" | ||
| "strconv" | ||
| "time" | ||
| @@ -665,6 +666,13 @@ | ||
| ) | ||
| return | ||
| } | ||
| if id < int(math.MinInt32) || id > int(math.MaxInt32) { | ||
| resp.Diagnostics.AddError( | ||
| "View ID Out of Range", | ||
| fmt.Sprintf("ID '%s' is outside of valid int32 range (%d to %d)", idStr, math.MinInt32, math.MaxInt32), | ||
| ) | ||
| return | ||
| } | ||
|
|
||
| readReq := &cxsdk.GetViewRequest{ | ||
| Id: wrapperspb.Int32(int32(id)), |
Copilot is powered by AI and may make mistakes. Always verify output.
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.
Description
Acceptance tests
Output from acceptance testing:
Release Note
Release note for CHANGELOG:
References
Community Note