Fix: check target is valid in rules (#210)

This commit is contained in:
beyondkmp 2019-06-20 11:03:50 +08:00 committed by Dreamacro
parent ba5eefb6dd
commit bcf5b21208
1 changed files with 6 additions and 2 deletions

View File

@ -157,7 +157,7 @@ func Parse(path string) (*Config, error) {
} }
config.Proxies = proxies config.Proxies = proxies
rules, err := parseRules(rawCfg) rules, err := parseRules(rawCfg, proxies)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -354,7 +354,7 @@ func parseProxies(cfg *rawConfig) (map[string]C.Proxy, error) {
return proxies, nil 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{} rules := []C.Rule{}
rulesConfig := cfg.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) 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) rule = trimArr(rule)
var parsed C.Rule var parsed C.Rule
switch rule[0] { switch rule[0] {