Skip to content

Commit

Permalink
fix: protect uint32 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
aauren committed Apr 14, 2021
1 parent 1816886 commit ef827d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pkg/controllers/routing/bgp_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package routing
import (
"context"
"errors"
"fmt"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -71,7 +72,10 @@ func (nrc *NetworkRoutingController) addPodCidrDefinedSet() error {
return err
}
if currentDefinedSet == nil {
cidrLen, _ := strconv.Atoi(strings.Split(nrc.podCidr, "/")[1])
cidrLen, err := strconv.Atoi(strings.Split(nrc.podCidr, "/")[1])
if err != nil || cidrLen < 0 || cidrLen > 32 {
return fmt.Errorf("the pod CIDR IP given is not a proper mask: %d", cidrLen)
}
podCidrDefinedSet := &gobgpapi.DefinedSet{
DefinedType: gobgpapi.DefinedType_PREFIX,
Name: "podcidrdefinedset",
Expand Down
9 changes: 6 additions & 3 deletions pkg/controllers/routing/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,12 @@ func (nrc *NetworkRoutingController) advertisePodRoute() error {

cidrStr := strings.Split(nrc.podCidr, "/")
subnet := cidrStr[0]
cidrLen, _ := strconv.Atoi(cidrStr[1])
cidrLen, err := strconv.Atoi(cidrStr[1])
if err != nil || cidrLen < 0 || cidrLen > 32 {
return fmt.Errorf("the pod CIDR IP given is not a proper mask: %d", cidrLen)
}
if nrc.isIpv6 {
klog.V(2).Infof("Advertising route: '%s/%s via %s' to peers", subnet, strconv.Itoa(cidrLen), nrc.nodeIP.String())
klog.V(2).Infof("Advertising route: '%s/%d via %s' to peers", subnet, cidrLen, nrc.nodeIP.String())

v6Family := &gobgpapi.Family{
Afi: gobgpapi.Family_AFI_IP6,
Expand Down Expand Up @@ -472,7 +475,7 @@ func (nrc *NetworkRoutingController) advertisePodRoute() error {
}
} else {

klog.V(2).Infof("Advertising route: '%s/%s via %s' to peers", subnet, strconv.Itoa(cidrLen), nrc.nodeIP.String())
klog.V(2).Infof("Advertising route: '%s/%d via %s' to peers", subnet, cidrLen, nrc.nodeIP.String())
nlri, _ := ptypes.MarshalAny(&gobgpapi.IPAddressPrefix{
PrefixLen: uint32(cidrLen),
Prefix: cidrStr[0],
Expand Down

0 comments on commit ef827d3

Please sign in to comment.