From f2c4fdb0aeddf56a2880310ea5ae1206aead0a1c Mon Sep 17 00:00:00 2001 From: Sam Cook Date: Fri, 15 Dec 2023 05:29:40 +1300 Subject: [PATCH] Fix nil pointer dereference segfault when passing "null" config json to cloudflared tunnel ingress validate (#1070) --- ingress/ingress.go | 2 +- ingress/ingress_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ingress/ingress.go b/ingress/ingress.go index e2498842..60ee87ac 100644 --- a/ingress/ingress.go +++ b/ingress/ingress.go @@ -85,7 +85,7 @@ type Ingress struct { // ParseIngress parses ingress rules, but does not send HTTP requests to the origins. func ParseIngress(conf *config.Configuration) (Ingress, error) { - if len(conf.Ingress) == 0 { + if conf == nil || len(conf.Ingress) == 0 { return Ingress{}, ErrNoIngressRules } return validateIngress(conf.Ingress, originRequestFromConfig(conf.OriginRequest)) diff --git a/ingress/ingress_test.go b/ingress/ingress_test.go index affbbf97..109cb353 100644 --- a/ingress/ingress_test.go +++ b/ingress/ingress_test.go @@ -43,6 +43,11 @@ ingress: require.Equal(t, "https", s.scheme) } +func TestParseIngressNilConfig(t *testing.T) { + _, err := ParseIngress(nil) + require.Error(t, err) +} + func TestParseIngress(t *testing.T) { localhost8000 := MustParseURL(t, "https://localhost:8000") localhost8001 := MustParseURL(t, "https://localhost:8001")