From: Bryan C. Mills Date: Thu, 11 Apr 2019 19:42:21 +0000 (-0400) Subject: os: fix aliasing bug in RemoveAllTestHook restoration X-Git-Tag: go1.13beta1~732 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2ebdb5ec0652742afe7f0c58f708ca5128ef5d5e;p=gostls13.git os: fix aliasing bug in RemoveAllTestHook restoration The code to swap RemoveAllTestHook in and out in TestRemoveAllWithMoreErrorThanReqSize was making a copy of the RemoveAllTestHook pointer, then attempting to restore by loading from the copy of that pointer. Since the two copies of the pointer aliased the same address, the restore operation had no effect, and any RemoveAll tests that happened to run after TestRemoveAllWithMoreErrorThanReqSize would fail. Fixes #31421 Change-Id: I7028475f5ceb3b0a2fa69d22af8d3379508c4531 Reviewed-on: https://go-review.googlesource.com/c/go/+/171777 Run-TryBot: Bryan C. Mills Reviewed-by: Brad Fitzpatrick --- diff --git a/src/os/removeall_test.go b/src/os/removeall_test.go index eb9459445c..96e0fc5a55 100644 --- a/src/os/removeall_test.go +++ b/src/os/removeall_test.go @@ -412,13 +412,14 @@ func TestRemoveAllWithMoreErrorThanReqSize(t *testing.T) { if testing.Short() { t.Skip("skipping in short mode") } - oldRemoveAllTestHook := RemoveAllTestHook + + defer func(oldHook func(error) error) { + *RemoveAllTestHook = oldHook + }(*RemoveAllTestHook) + *RemoveAllTestHook = func(err error) error { return errors.New("error from RemoveAllTestHook") } - defer func() { - *RemoveAllTestHook = *oldRemoveAllTestHook - }() tmpDir, err := ioutil.TempDir("", "TestRemoveAll-") if err != nil {