Skip to content

Commit

Permalink
Fix: check target is valid in rules (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondkmp authored and Dreamacro committed Jun 20, 2019
1 parent ba5eefb commit bcf5b21
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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] {
Expand Down

0 comments on commit bcf5b21

Please sign in to comment.