Skip to content

Commit f31504a

Browse files
committed
fix: add safety checks to prevent index-out-of-range panics in CdHandler
1 parent 78045b5 commit f31504a

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

pkg/pipeline/CdHandler.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -878,24 +878,13 @@ func (impl *CdHandlerImpl) FetchAppDeploymentStatusForEnvironments(request resou
878878
objects := impl.enforcerUtil.GetAppAndEnvObjectByPipelineIds(pipelineIds)
879879
pipelineIds = []int{}
880880
for _, object := range objects {
881-
// Safety check to prevent index out of range panic
882-
if len(object) >= 2 {
883-
appObjectArr = append(appObjectArr, object[0])
884-
envObjectArr = append(envObjectArr, object[1])
885-
} else {
886-
impl.Logger.Warnw("skipping object with insufficient elements", "object", object)
887-
}
881+
appObjectArr = append(appObjectArr, object[0])
882+
envObjectArr = append(envObjectArr, object[1])
888883
}
889884
appResults, envResults := request.CheckAuthBatch(token, appObjectArr, envObjectArr)
890885
for _, pipeline := range cdPipelines {
891-
// Safety check to prevent index out of range panic
892-
objectArr, ok := objects[pipeline.Id]
893-
if !ok || len(objectArr) < 2 {
894-
impl.Logger.Warnw("skipping pipeline with missing object data", "pipelineId", pipeline.Id)
895-
continue
896-
}
897-
appObject := objectArr[0]
898-
envObject := objectArr[1]
886+
appObject := objects[pipeline.Id][0]
887+
envObject := objects[pipeline.Id][1]
899888
if !(appResults[appObject] && envResults[envObject]) {
900889
// if user unauthorized, skip items
901890
continue

0 commit comments

Comments
 (0)