Skip to content

Commit

Permalink
fixes osrg#2645 Panic when adding FlowspecComponentItem with to large…
Browse files Browse the repository at this point in the history
… value
  • Loading branch information
aelg authored and FUJITA Tomonori committed May 22, 2023
1 parent ba162b3 commit 9c969eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
7 changes: 2 additions & 5 deletions pkg/packet/bgp/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4374,13 +4374,10 @@ func NewFlowSpecComponentItem(op uint8, value uint64) *FlowSpecComponentItem {
return uint32(i)
}
}
// return invalid order
return 4
// Return 8 octet order
return 3
}()
}
if order > 3 {
return nil
}
v.Op = uint8(uint32(v.Op) | order<<4)
return v
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/packet/bgp/bgp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package bgp
import (
"bytes"
"encoding/binary"
"math"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -443,6 +444,28 @@ func Test_FlowSpecNlri(t *testing.T) {
assert.Equal(n1, n2)
}

func Test_NewFlowSpecComponentItemLength(t *testing.T) {
item := NewFlowSpecComponentItem(0, 0)
assert.Equal(t, 1, item.Len())
item = NewFlowSpecComponentItem(0, math.MaxUint8)
assert.Equal(t, 1, item.Len())

item = NewFlowSpecComponentItem(0, math.MaxUint8+1)
assert.Equal(t, 2, item.Len())
item = NewFlowSpecComponentItem(0, math.MaxUint16)
assert.Equal(t, 2, item.Len())

item = NewFlowSpecComponentItem(0, math.MaxUint16+1)
assert.Equal(t, 4, item.Len())
item = NewFlowSpecComponentItem(0, math.MaxUint32)
assert.Equal(t, 4, item.Len())

item = NewFlowSpecComponentItem(0, math.MaxUint32+1)
assert.Equal(t, 8, item.Len())
item = NewFlowSpecComponentItem(0, math.MaxUint64)
assert.Equal(t, 8, item.Len())
}

func Test_LinkBandwidthExtended(t *testing.T) {
assert := assert.New(t)
exts := make([]ExtendedCommunityInterface, 0)
Expand Down

0 comments on commit 9c969eb

Please sign in to comment.