Skip to content

Commit

Permalink
Prevent checking beyond lsb in a network in a remove call (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
yl2chen authored Sep 21, 2020
1 parent 64ae714 commit 7ff5a0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ func (p *prefixTrie) remove(network rnet.Network) (RangerEntry, error) {
}
return entry, nil
}
if p.targetBitPosition() < 0 {
return nil, nil
}
bit, err := p.targetBitFromIP(network.Number)
if err != nil {
return nil, err
Expand Down
10 changes: 10 additions & 0 deletions trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ func TestPrefixTrieRemove(t *testing.T) {
"0.0.0.0/0 (target_pos:31:has_entry:false)",
"basic remove",
},
{
rnet.IPv4,
[]string{"192.168.0.1/32"},
[]string{"192.168.0.1/24"},
[]string{""},
[]string{"192.168.0.1/32"},
`0.0.0.0/0 (target_pos:31:has_entry:false)
| 1--> 192.168.0.1/32 (target_pos:-1:has_entry:true)`,
"remove from ranger that contains a single ip block",
},
{
rnet.IPv4,
[]string{"1.2.3.4/32", "1.2.3.5/32"},
Expand Down

0 comments on commit 7ff5a0e

Please sign in to comment.