Skip to content

Commit 5e4914e

Browse files
tas50claude
andcommitted
Fix nil pointer dereference in longTermRetentionPolicy
Extract weeklyRetention, monthlyRetention, and yearlyRetention into local variables inside the policy.Properties nil guard. Previously these fields were accessed directly on policy.Properties in the CreateResource call, which would panic if Properties was nil. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3fbbc64 commit 5e4914e

File tree

1 file changed

+11
-5
lines changed
  • providers/azure/resources

1 file changed

+11
-5
lines changed

providers/azure/resources/sql.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -844,16 +844,22 @@ func (a *mqlAzureSubscriptionSqlServiceDatabase) longTermRetentionPolicy() (*mql
844844
}
845845

846846
var weekOfYear int64
847-
if policy.Properties != nil && policy.Properties.WeekOfYear != nil {
848-
weekOfYear = int64(*policy.Properties.WeekOfYear)
847+
var weeklyRetention, monthlyRetention, yearlyRetention *string
848+
if policy.Properties != nil {
849+
weeklyRetention = policy.Properties.WeeklyRetention
850+
monthlyRetention = policy.Properties.MonthlyRetention
851+
yearlyRetention = policy.Properties.YearlyRetention
852+
if policy.Properties.WeekOfYear != nil {
853+
weekOfYear = int64(*policy.Properties.WeekOfYear)
854+
}
849855
}
850856

851857
res, err := CreateResource(a.MqlRuntime, "azure.subscription.sqlService.database.longtermretentionpolicy",
852858
map[string]*llx.RawData{
853859
"id": llx.StringDataPtr(policy.ID),
854-
"weeklyRetention": llx.StringDataPtr(policy.Properties.WeeklyRetention),
855-
"monthlyRetention": llx.StringDataPtr(policy.Properties.MonthlyRetention),
856-
"yearlyRetention": llx.StringDataPtr(policy.Properties.YearlyRetention),
860+
"weeklyRetention": llx.StringDataPtr(weeklyRetention),
861+
"monthlyRetention": llx.StringDataPtr(monthlyRetention),
862+
"yearlyRetention": llx.StringDataPtr(yearlyRetention),
857863
"weekOfYear": llx.IntData(weekOfYear),
858864
})
859865
if err != nil {

0 commit comments

Comments
 (0)