Skip to content

Commit 6c0d368

Browse files
committed
fixes osrg#2645 Panic when adding FlowspecComponentItem with to large value
1 parent 2fbfee5 commit 6c0d368

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

pkg/packet/bgp/bgp.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -4374,13 +4374,10 @@ func NewFlowSpecComponentItem(op uint8, value uint64) *FlowSpecComponentItem {
43744374
return uint32(i)
43754375
}
43764376
}
4377-
// return invalid order
4378-
return 4
4377+
// Return 8 octet order
4378+
return 3
43794379
}()
43804380
}
4381-
if order > 3 {
4382-
return nil
4383-
}
43844381
v.Op = uint8(uint32(v.Op) | order<<4)
43854382
return v
43864383
}

pkg/packet/bgp/bgp_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package bgp
1818
import (
1919
"bytes"
2020
"encoding/binary"
21+
"math"
2122
"net"
2223
"os"
2324
"path/filepath"
@@ -443,6 +444,28 @@ func Test_FlowSpecNlri(t *testing.T) {
443444
assert.Equal(n1, n2)
444445
}
445446

447+
func Test_NewFlowSpecComponentItemLength(t *testing.T) {
448+
item := NewFlowSpecComponentItem(0, 0)
449+
assert.Equal(t, 1, item.Len())
450+
item = NewFlowSpecComponentItem(0, math.MaxUint8)
451+
assert.Equal(t, 1, item.Len())
452+
453+
item = NewFlowSpecComponentItem(0, math.MaxUint8+1)
454+
assert.Equal(t, 2, item.Len())
455+
item = NewFlowSpecComponentItem(0, math.MaxUint16)
456+
assert.Equal(t, 2, item.Len())
457+
458+
item = NewFlowSpecComponentItem(0, math.MaxUint16+1)
459+
assert.Equal(t, 4, item.Len())
460+
item = NewFlowSpecComponentItem(0, math.MaxUint32)
461+
assert.Equal(t, 4, item.Len())
462+
463+
item = NewFlowSpecComponentItem(0, math.MaxUint32+1)
464+
assert.Equal(t, 8, item.Len())
465+
item = NewFlowSpecComponentItem(0, math.MaxUint64)
466+
assert.Equal(t, 8, item.Len())
467+
}
468+
446469
func Test_LinkBandwidthExtended(t *testing.T) {
447470
assert := assert.New(t)
448471
exts := make([]ExtendedCommunityInterface, 0)

0 commit comments

Comments
 (0)