From 4120d9c01f758663ea64cf65daebc44da61eb4f0 Mon Sep 17 00:00:00 2001 From: zjhe Date: Fri, 7 Apr 2023 10:00:40 +0800 Subject: [PATCH] add length check to avoid potential index out of range panic --- .../appservice/helpers/linux_web_app_schema.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/services/appservice/helpers/linux_web_app_schema.go b/internal/services/appservice/helpers/linux_web_app_schema.go index f752b99ac248..ea0b035bfd31 100644 --- a/internal/services/appservice/helpers/linux_web_app_schema.go +++ b/internal/services/appservice/helpers/linux_web_app_schema.go @@ -1142,6 +1142,16 @@ func expandAutoHealSettingsLinux(autoHealSettings []AutoHealSettingLinux) *web.A 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{ @@ -1193,10 +1203,6 @@ func expandAutoHealSettingsLinux(autoHealSettings []AutoHealSettingLinux) *web.A result.Triggers.StatusCodesRange = &statusCodeRangeTriggers } - action := autoHeal.Actions[0] - result.Actions.ActionType = web.AutoHealActionType(action.ActionType) - result.Actions.MinProcessExecutionTime = pointer.To(action.MinimumProcessTime) - return result }