From 1e6f0bb608dcac92b7c9200e4b88bf219353772e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 17 Jul 2023 10:04:32 -0700 Subject: [PATCH] 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 --- net/art/table_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/art/table_test.go b/net/art/table_test.go index 37b3cefc6..0885b3c02 100644 --- a/net/art/table_test.go +++ b/net/art/table_test.go @@ -1115,6 +1115,7 @@ type slowPrefixEntry[T any] struct { } func (t *slowPrefixTable[T]) delete(pfx netip.Prefix) { + pfx = pfx.Masked() ret := make([]slowPrefixEntry[T], 0, len(t.prefixes)) for _, ent := range t.prefixes { 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) { - for _, ent := range t.prefixes { + pfx = pfx.Masked() + for i, ent := range t.prefixes { if ent.pfx == pfx { - ent.val = val + t.prefixes[i].val = val return } }