From 7ae204d42680bb2c666726c89d3f7b09aa651699 Mon Sep 17 00:00:00 2001 From: Alexander Matyushentsev Date: Mon, 30 Mar 2020 14:27:43 -0700 Subject: [PATCH] fix: avoid nil pointer dereference in badge handler (#3316) --- server/badge/badge.go | 6 ++++-- server/badge/badge_test.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server/badge/badge.go b/server/badge/badge.go index fd3ddad1ac..6b6eec5eb8 100644 --- a/server/badge/badge.go +++ b/server/badge/badge.go @@ -76,7 +76,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if app, err := h.appClientset.ArgoprojV1alpha1().Applications(h.namespace).Get(name[0], v1.GetOptions{}); err == nil { health = app.Status.Health.Status status = app.Status.Sync.Status - revision = app.Status.OperationState.SyncResult.Revision + if app.Status.OperationState != nil && app.Status.OperationState.SyncResult != nil { + revision = app.Status.OperationState.SyncResult.Revision + } } else if errors.IsNotFound(err) { notFound = true } @@ -115,7 +117,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { badge = replaceFirstGroupSubMatch(leftTextPattern, badge, leftText) badge = replaceFirstGroupSubMatch(rightTextPattern, badge, rightText) - if !notFound && revisionEnabled { + if !notFound && revisionEnabled && revision != "" { // Increase width of SVG and enable display of revision components badge = svgWidthPattern.ReplaceAllString(badge, fmt.Sprintf(`