summaryrefslogtreecommitdiffhomepage
path: root/api/grpc_server.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-09 10:47:56 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-13 11:20:07 +0900
commite984c6902d1a494d2354caf622891258c1f85c17 (patch)
treeff566a864ff0d2de245ab502bd6d3625b132a4db /api/grpc_server.go
parentab8ba077e5882220c652e255507f8450ca61d664 (diff)
api/grpc_server: Avoid index error when invalid set-med value
Currently, with a invalid "set-med" value in a policy action, GoBGP will raise panic of "index out of range" because the unmatched regular expression is not handled. This patch fixes to handle errors during parsing the given med value. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'api/grpc_server.go')
-rw-r--r--api/grpc_server.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index 161bc826..5b10b055 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -1606,17 +1606,24 @@ func toStatementApi(s *config.Statement) *Statement {
Communities: s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList}
}(),
Med: func() *MedAction {
- if len(string(s.Actions.BgpActions.SetMed)) == 0 {
+ medStr := strings.TrimSpace(string(s.Actions.BgpActions.SetMed))
+ if len(medStr) == 0 {
+ return nil
+ }
+ re := regexp.MustCompile("([+-]?)(\\d+)")
+ matches := re.FindStringSubmatch(medStr)
+ if len(matches) == 0 {
return nil
}
- exp := regexp.MustCompile("^(\\+|\\-)?(\\d+)$")
- elems := exp.FindStringSubmatch(string(s.Actions.BgpActions.SetMed))
action := MedActionType_MED_REPLACE
- switch elems[1] {
+ switch matches[1] {
case "+", "-":
action = MedActionType_MED_MOD
}
- value, _ := strconv.Atoi(string(s.Actions.BgpActions.SetMed))
+ value, err := strconv.Atoi(matches[1] + matches[2])
+ if err != nil {
+ return nil
+ }
return &MedAction{
Value: int64(value),
Type: action,