net/art: fix slowPrefixTable bugs found by fuzzing

One is a straight "I forgot how to Go" bug, the others are semantic
mismatches with the main implementation around masking the prefixes
passed to insert/delete.

Updates #7781

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2023-07-17 10:04:32 -07:00 committed by Dave Anderson
parent aaca911904
commit 1e6f0bb608

View File

@ -1115,6 +1115,7 @@ type slowPrefixEntry[T any] struct {
} }
func (t *slowPrefixTable[T]) delete(pfx netip.Prefix) { func (t *slowPrefixTable[T]) delete(pfx netip.Prefix) {
pfx = pfx.Masked()
ret := make([]slowPrefixEntry[T], 0, len(t.prefixes)) ret := make([]slowPrefixEntry[T], 0, len(t.prefixes))
for _, ent := range t.prefixes { for _, ent := range t.prefixes {
if ent.pfx == pfx { if ent.pfx == pfx {
@ -1126,9 +1127,10 @@ func (t *slowPrefixTable[T]) delete(pfx netip.Prefix) {
} }
func (t *slowPrefixTable[T]) insert(pfx netip.Prefix, val *T) { func (t *slowPrefixTable[T]) insert(pfx netip.Prefix, val *T) {
for _, ent := range t.prefixes { pfx = pfx.Masked()
for i, ent := range t.prefixes {
if ent.pfx == pfx { if ent.pfx == pfx {
ent.val = val t.prefixes[i].val = val
return return
} }
} }