feat: Update Search Deployment Resource#1534
Conversation
| @@ -42,6 +42,17 @@ func HandleStateTransition(connV2 admin20231115014.APIClient, currentModel *Mode | |||
| } | |||
There was a problem hiding this comment.
Semgrep identified an issue in your code:
Variable resp is likely modified and later used on error. In some cases this could result in panics due to a nil dereference
To resolve this comment:
✨ Commit Assistant Fix Suggestion
- Add a nil check for
respbefore accessing its fields inside theif err != nilblock. - Update the first inner
ifcondition toif targetState == constants.DeletedState && resp != nil && resp.StatusCode == http.StatusBadRequest && strings.Contains(err.Error(), SearchDeploymentDoesNotExistsError). - Update the final error return to also ensure
respis not nil if it will be dereferenced, for example:return progressevent.GetFailedEventByResponse(err.Error(), resp)becomesreturn progressevent.GetFailedEventByResponse(err.Error(), resp)if that function handles nil safely, otherwise checkif resp != nil { ... } else { ... }.
This change prevents a potential panic if resp is nil by ensuring the code only accesses resp.StatusCode when resp is not nil.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by invalid-usage-of-modified-variable.
🛟 Help? Slack #semgrep-help or go/semgrep-help.
Resolution Options:
- Fix the code
- Reply
/fp $reason(if security gap doesn’t exist) - Reply
/ar $reason(if gap is valid but intentional; add mitigations/monitoring) - Reply
/other $reason(e.g., test-only)
You can view more details about this finding in the Semgrep AppSec Platform.
b42d703 to
b2964ed
Compare
There was a problem hiding this comment.
LGTM once semgrep comment is addressed
@sivaram-mongodb can you also add a link to the test stack in the JIRA ticket?
Proposed changes
cfn-testing
Published to AWS private registry
Stack Testing
Atlas - Before Creation
Atlas - After Creation
Jira ticket: CLOUDP-369807
Please include a summary of the fix/feature/change, including any relevant motivation and context.
Link to any related issue(s):
Type of change:
expected)
Manual QA performed:
Required Checklist:
make fmtand formatted my codeworks in Atlas
Further comments