From b1bed7623dd47e33c974f4485567c9723859aad0 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Sun, 21 Nov 2021 17:44:03 +0800 Subject: [PATCH] Fix: provider filter potential panic --- adapter/provider/parser.go | 2 +- adapter/provider/provider.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/adapter/provider/parser.go b/adapter/provider/parser.go index bd393569..d91aa4a1 100644 --- a/adapter/provider/parser.go +++ b/adapter/provider/parser.go @@ -60,5 +60,5 @@ func ParseProxyProvider(name string, mapping map[string]interface{}) (types.Prox interval := time.Duration(uint(schema.Interval)) * time.Second filter := schema.Filter - return NewProxySetProvider(name, interval, filter, vehicle, hc), nil + return NewProxySetProvider(name, interval, filter, vehicle, hc) } diff --git a/adapter/provider/provider.go b/adapter/provider/provider.go index c042b2de..6a5e3052 100644 --- a/adapter/provider/provider.go +++ b/adapter/provider/provider.go @@ -96,7 +96,11 @@ func stopProxyProvider(pd *ProxySetProvider) { pd.fetcher.Destroy() } -func NewProxySetProvider(name string, interval time.Duration, filter string, vehicle types.Vehicle, hc *HealthCheck) *ProxySetProvider { +func NewProxySetProvider(name string, interval time.Duration, filter string, vehicle types.Vehicle, hc *HealthCheck) (*ProxySetProvider, error) { + if _, err := regexp.Compile(filter); err != nil { + return nil, fmt.Errorf("invalid filter regex: %w", err) + } + if hc.auto() { go hc.process() } @@ -150,7 +154,7 @@ func NewProxySetProvider(name string, interval time.Duration, filter string, veh wrapper := &ProxySetProvider{pd} runtime.SetFinalizer(wrapper, stopProxyProvider) - return wrapper + return wrapper, nil } // for auto gc