]> Cypherpunks repositories - gostls13.git/commit
reflect: fix mutability of non-exported embedded fields
authorMatthew Dempsky <mdempsky@google.com>
Tue, 26 Sep 2017 21:55:41 +0000 (14:55 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 27 Sep 2017 18:03:28 +0000 (18:03 +0000)
commit6471ace2ea449ea9b7e5b77b9e59c97eafa6392f
treed2414c8ac1dc99d266c285477b8763cbd56b5d9b
parenta714470cce03b28321a9dbcdbf34a99ab59deb75
reflect: fix mutability of non-exported embedded fields

The reflect API normally grants only read-only access to non-exported
fields, but it specially handles non-exported embedded fields so that
users can still fully access promoted fields and methods. For example,
if v.Field(i) refers to a non-exported embedded field, it would be
limited to RO access. But if v.Field(i).Field(j) is an exported field,
then the resulting Value will have full access.

However, the way this was implemented allowed other operations to be
interspersed between the Field calls, which could grant inappropriate
access.

Relatedly, Elem() is safe to use on pointer-embeddings, but it was
also being allowed on embeddings of interface types. This is
inappropriate because it could allow accessing methods of the dynamic
value's complete method set, not just those that were promoted via the
interface embedding.

Fixes #22031.
Fixes #22053.

Change-Id: I9db9be88583f1c1d80c1b4705a76f23a4379182f
Reviewed-on: https://go-review.googlesource.com/66331
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/reflect/all_test.go
src/reflect/value.go