From bcf5b21208a4b6a7f77d4b308d2cf45db815bb95 Mon Sep 17 00:00:00 2001 From: beyondkmp Date: Thu, 20 Jun 2019 11:03:50 +0800 Subject: [PATCH] Fix: check target is valid in rules (#210) --- config/config.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index e89e934..8b4e0bc 100644 --- a/config/config.go +++ b/config/config.go @@ -157,7 +157,7 @@ func Parse(path string) (*Config, error) { } config.Proxies = proxies - rules, err := parseRules(rawCfg) + rules, err := parseRules(rawCfg, proxies) if err != nil { return nil, err } @@ -354,7 +354,7 @@ func parseProxies(cfg *rawConfig) (map[string]C.Proxy, error) { return proxies, nil } -func parseRules(cfg *rawConfig) ([]C.Rule, error) { +func parseRules(cfg *rawConfig, proxies map[string]C.Proxy) ([]C.Rule, error) { rules := []C.Rule{} rulesConfig := cfg.Rule @@ -376,6 +376,10 @@ func parseRules(cfg *rawConfig) ([]C.Rule, error) { return nil, fmt.Errorf("Rules[%d] [%s] error: format invalid", idx, line) } + if _, ok := proxies[target]; !ok { + return nil, fmt.Errorf("Rules[%d] [%s] error: proxy [%s] not found", idx, line, target) + } + rule = trimArr(rule) var parsed C.Rule switch rule[0] {