util/deephash: prevent infinite loop on map cycle

Fixes #2340

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-07-06 21:41:18 -07:00
committed by Brad Fitzpatrick
parent aceaa70b16
commit 3962744450
2 changed files with 34 additions and 0 deletions

View File

@ -226,3 +226,15 @@ func TestSHA256EqualHex(t *testing.T) {
}
}
}
// verify this doesn't loop forever, as it used to (Issue 2340)
func TestMapCyclicFallback(t *testing.T) {
type T struct {
M map[string]interface{}
}
v := &T{
M: map[string]interface{}{},
}
v.M["m"] = v.M
Hash(v)
}