]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.10] encoding/json: avoid assuming side-effect free reflect.Value...
authorJoe Tsai <joetsai@digital-static.net>
Wed, 28 Feb 2018 21:45:06 +0000 (13:45 -0800)
committerAndrew Bonventre <andybons@golang.org>
Thu, 29 Mar 2018 06:07:44 +0000 (06:07 +0000)
commit853155f384e570635846b508d2fde7899d8d1612
treedc2888ec3b03163ba41fb53d58959e70ea9135d1
parentb8c62b1a89ad49000c282657f6e4192e34231be1
[release-branch.go1.10] encoding/json: avoid assuming side-effect free reflect.Value.Addr().Elem()

Consider the following:
type child struct{ Field string }
type parent struct{ child }

p := new(parent)
v := reflect.ValueOf(p).Elem().Field(0)
v.Field(0).SetString("hello")           // v.Field = "hello"
v = v.Addr().Elem()                     // v = *(&v)
v.Field(0).SetString("goodbye")         // v.Field = "goodbye"

It would appear that v.Addr().Elem() should have the same value, and
that it would be safe to set "goodbye".
However, after CL 66331, any interspersed calls between Field calls
causes the RO flag to be set.
Thus, setting to "goodbye" actually causes a panic.

That CL affects decodeState.indirect which assumes that back-to-back
Value.Addr().Elem() is side-effect free. We fix that logic to keep
track of the Addr() and Elem() calls and set v back to the original
after a full round-trip has occured.

Fixes #24152
Updates #24153

Change-Id: Ie50f8fe963f00cef8515d89d1d5cbc43b76d9f9c
Reviewed-on: https://go-review.googlesource.com/97796
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-on: https://go-review.googlesource.com/102784
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/encoding/json/decode.go
src/encoding/json/decode_test.go