Skip to content

Commit

Permalink
Fix crash on ListPathRequest with malformed prefix
Browse files Browse the repository at this point in the history
When ListPathRequest is done by a gRPC client including a malformed prefix,
 the server would crash an invalid memory address reference.

This commit avoid the crash by checking whether the parseCIDR method returned
an error.
  • Loading branch information
rodrigopv committed Aug 4, 2023
1 parent d3a46b8 commit 909e081
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions pkg/packet/bgp/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9582,7 +9582,14 @@ func NewPrefixFromRouteFamily(afi uint16, safi uint8, prefixStr ...string) (pref
family := AfiSafiToRouteFamily(afi, safi)

f := func(s string) AddrPrefixInterface {
addr, net, _ := net.ParseCIDR(s)
addr, net, err := net.ParseCIDR(s)
if err != nil {
switch family {
case RF_IPv4_UC, RF_IPv4_MC:
return NewIPAddrPrefix(0, "")
}
return NewIPv6AddrPrefix(0, "")
}
len, _ := net.Mask.Size()
switch family {
case RF_IPv4_UC, RF_IPv4_MC:
Expand All @@ -9593,17 +9600,9 @@ func NewPrefixFromRouteFamily(afi uint16, safi uint8, prefixStr ...string) (pref

switch family {
case RF_IPv4_UC, RF_IPv4_MC:
if len(prefixStr) > 0 {
prefix = f(prefixStr[0])
} else {
prefix = NewIPAddrPrefix(0, "")
}
prefix = f(prefixStr[0])
case RF_IPv6_UC, RF_IPv6_MC:
if len(prefixStr) > 0 {
prefix = f(prefixStr[0])
} else {
prefix = NewIPv6AddrPrefix(0, "")
}
prefix = f(prefixStr[0])
case RF_IPv4_VPN:
prefix = NewLabeledVPNIPAddrPrefix(0, "", *NewMPLSLabelStack(), nil)
case RF_IPv6_VPN:
Expand Down

0 comments on commit 909e081

Please sign in to comment.