From 24ef5e83bffc4ac6f4355aab04fd4dbafd7423da Mon Sep 17 00:00:00 2001 From: "R.B. Boyer" Date: Mon, 18 Sep 2023 15:05:19 -0500 Subject: [PATCH] ignore nil pointer deref --- internal/mesh/internal/types/upstreams.go | 3 +++ internal/mesh/internal/types/upstreams_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/internal/mesh/internal/types/upstreams.go b/internal/mesh/internal/types/upstreams.go index 90f196243905..54baeceebff7 100644 --- a/internal/mesh/internal/types/upstreams.go +++ b/internal/mesh/internal/types/upstreams.go @@ -47,6 +47,9 @@ func MutateUpstreams(res *pbresource.Resource) error { changed := false for _, dest := range destinations.Upstreams { + if dest.DestinationRef == nil { + continue // skip; let the validation hook error out instead + } if dest.DestinationRef.Tenancy != nil && !isLocalPeer(dest.DestinationRef.Tenancy.PeerName) { // TODO(peering/v2): remove this bypass when we know what to do with // non-local peer references. diff --git a/internal/mesh/internal/types/upstreams_test.go b/internal/mesh/internal/types/upstreams_test.go index 5e5e7e68c5ad..ca4b2ce9b4f1 100644 --- a/internal/mesh/internal/types/upstreams_test.go +++ b/internal/mesh/internal/types/upstreams_test.go @@ -48,6 +48,18 @@ func TestMutateUpstreams(t *testing.T) { data: &pbmesh.Upstreams{}, expect: &pbmesh.Upstreams{}, }, + "invalid/nil dest ref": { + data: &pbmesh.Upstreams{ + Upstreams: []*pbmesh.Upstream{ + {DestinationRef: nil}, + }, + }, + expect: &pbmesh.Upstreams{ // untouched + Upstreams: []*pbmesh.Upstream{ + {DestinationRef: nil}, + }, + }, + }, "dest ref tenancy defaulting": { tenancy: newTestTenancy("foo.bar"), data: &pbmesh.Upstreams{