From 3e34e2af6f78bb7161d4653ca8e0d541ee89d58c Mon Sep 17 00:00:00 2001 From: calebak404 <78181572+calebak404@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:05:26 -0500 Subject: [PATCH 1/2] add length check to avoid panic add length check to match linux_web_app to avoid potential panic in windows_web_app linux change done in #21328 --- internal/services/appservice/helpers/auto_heal.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/services/appservice/helpers/auto_heal.go b/internal/services/appservice/helpers/auto_heal.go index 06a00c5fa62e..62e34c832af4 100644 --- a/internal/services/appservice/helpers/auto_heal.go +++ b/internal/services/appservice/helpers/auto_heal.go @@ -401,7 +401,17 @@ func expandAutoHealSettingsWindows(autoHealSettings []AutoHealSettingWindows) *w } autoHeal := autoHealSettings[0] + + if len(autoHeal.actions) > 0 { + action := autoHeal.Actions[0] + result.Actions.ActionType = web.AutoHealActionType(action.ActionType) + result.Actions.MinProcessExecutionTime = pointer.To(action.MinimumProcessTime) + } + if len(autoHeal.Triggers) == 0 { + return result + } + triggers := autoHeal.Triggers[0] if len(triggers.Requests) == 1 { result.Triggers.Requests = &web.RequestsBasedTrigger{ @@ -462,10 +472,7 @@ func expandAutoHealSettingsWindows(autoHealSettings []AutoHealSettingWindows) *w result.Triggers.StatusCodes = &statusCodeTriggers result.Triggers.StatusCodesRange = &statusCodeRangeTriggers } - - action := autoHeal.Actions[0] - result.Actions.ActionType = web.AutoHealActionType(action.ActionType) - result.Actions.MinProcessExecutionTime = pointer.To(action.MinimumProcessTime) + if len(action.CustomAction) != 0 { customAction := action.CustomAction[0] result.Actions.CustomAction = &web.AutoHealCustomAction{ From 933226f8b0ac47f2c01477157f7ede660a376248 Mon Sep 17 00:00:00 2001 From: calebak404 <78181572+calebak404@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:16:24 +0000 Subject: [PATCH 2/2] fixup --- .../services/appservice/helpers/auto_heal.go | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/internal/services/appservice/helpers/auto_heal.go b/internal/services/appservice/helpers/auto_heal.go index 62e34c832af4..986aefe38f5e 100644 --- a/internal/services/appservice/helpers/auto_heal.go +++ b/internal/services/appservice/helpers/auto_heal.go @@ -401,17 +401,24 @@ func expandAutoHealSettingsWindows(autoHealSettings []AutoHealSettingWindows) *w } autoHeal := autoHealSettings[0] - - if len(autoHeal.actions) > 0 { + + if len(autoHeal.Actions) > 0 { action := autoHeal.Actions[0] result.Actions.ActionType = web.AutoHealActionType(action.ActionType) result.Actions.MinProcessExecutionTime = pointer.To(action.MinimumProcessTime) + if len(action.CustomAction) != 0 { + customAction := action.CustomAction[0] + result.Actions.CustomAction = &web.AutoHealCustomAction{ + Exe: pointer.To(customAction.Executable), + Parameters: pointer.To(customAction.Parameters), + } + } } if len(autoHeal.Triggers) == 0 { return result } - + triggers := autoHeal.Triggers[0] if len(triggers.Requests) == 1 { result.Triggers.Requests = &web.RequestsBasedTrigger{ @@ -472,14 +479,6 @@ func expandAutoHealSettingsWindows(autoHealSettings []AutoHealSettingWindows) *w result.Triggers.StatusCodes = &statusCodeTriggers result.Triggers.StatusCodesRange = &statusCodeRangeTriggers } - - if len(action.CustomAction) != 0 { - customAction := action.CustomAction[0] - result.Actions.CustomAction = &web.AutoHealCustomAction{ - Exe: pointer.To(customAction.Executable), - Parameters: pointer.To(customAction.Parameters), - } - } return result }