Skip to content

Commit

Permalink
v1.9.x - NPE (#6748)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstine committed Jul 18, 2022
1 parent 075f1e6 commit 2d68055
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
6 changes: 6 additions & 0 deletions changelog/v1.9.20/handle-npe-markperfilerconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/gloo/issues/6534
description: |
Fix bug where NPE occurs when the destination is nil in the RouteActions.
resolvesIssue: false
14 changes: 9 additions & 5 deletions projects/gloo/pkg/plugins/pluginutils/per_filter_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@ func MarkPerFilterConfig(
// intentionally ignored because destination is not specified at runtime, so perFilterConfig is useless
case *v1.RouteAction_ClusterHeader:
return nil
default:
err = errors.New("unexpected destination type that is nil")
destination := inAction.GetDestination()
if destination != nil {
err = errors.Errorf("unexpected destination type %v", reflect.TypeOf(destination).Name())
}
logger := contextutils.LoggerFrom(ctx)
logger.DPanic("error: %v", err)
return err
}

err = errors.Errorf("unexpected destination type %v", reflect.TypeOf(inAction.GetDestination()).Name())
logger := contextutils.LoggerFrom(ctx)
logger.DPanic("error: %v", err)
return err
}

func configureMultiDest(
Expand Down
25 changes: 25 additions & 0 deletions projects/gloo/pkg/plugins/pluginutils/per_filter_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,29 @@ var _ = Describe("TypedPerFilterConfig", func() {
})
})
})
Context("nil destination", func() {
BeforeEach(func() {
in = &v1.Route{
Action: &v1.Route_RouteAction{
RouteAction: &v1.RouteAction{},
},
}
out = &envoy_config_route_v3.Route{
Action: &envoy_config_route_v3.Route_Route{
Route: &envoy_config_route_v3.RouteAction{
ClusterSpecifier: &envoy_config_route_v3.RouteAction_Cluster{
Cluster: "test",
},
},
},
}
})
It("should not throw NPE when destination is nil", func() {
err := MarkPerFilterConfig(context.TODO(), &v1.ApiSnapshot{}, in, out, name, func(spec *v1.Destination) (proto.Message, error) {
return nil, nil
})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("unexpected destination type that is nil"))
})
})
})

0 comments on commit 2d68055

Please sign in to comment.