]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.14] runtime: make typehash match compiler generated hashes exactly
authorKeith Randall <khr@golang.org>
Fri, 6 Mar 2020 22:01:26 +0000 (14:01 -0800)
committerAlexander Rakoczy <alex@golang.org>
Tue, 10 Mar 2020 20:06:03 +0000 (20:06 +0000)
commit8e804f19b6fe56f42696c11c494763f199bb7a0f
tree2300bfe54b6160fffe400ad01008da3c514d8137
parent6717d27be2c1a67b1d7e8c7d426594c49a818b90
[release-branch.go1.14] runtime: make typehash match compiler generated hashes exactly

If typehash (used by reflect) does not match the built-in map's hash,
then problems occur. If a map is built using reflect, and then
assigned to a variable of map type, the hash function can change. That
causes very bad things.

This issue is rare. MapOf consults a cache of all types that occur in
the binary before making a new one. To make a true new map type (with
a hash function derived from typehash) that map type must not occur in
the binary anywhere. But to cause the bug, we need a variable of that
type in order to assign to it. The only way to make that work is to
use a named map type for the variable, so it is distinct from the
unnamed version that MapOf looks for.

Fixes #37721

Change-Id: I3537bfceca8cbfa1af84202f432f3c06953fe0ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/222357
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
(cherry picked from commit 2b8e60d464515634462ca472ca09c791e2cbf6ae)
Reviewed-on: https://go-review.googlesource.com/c/go/+/222778
src/cmd/compile/internal/gc/alg.go
src/runtime/alg.go
src/runtime/export_test.go
src/runtime/hash_test.go
test/fixedbugs/issue37716.go [new file with mode: 0644]