Skip to content

Commit

Permalink
ignore nil pointer deref
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer committed Sep 18, 2023
1 parent 82d84dd commit 24ef5e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/mesh/internal/types/upstreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions internal/mesh/internal/types/upstreams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 24ef5e8

Please sign in to comment.