]> Cypherpunks repositories - gostls13.git/commit
os: hide SetFinalizer from users of Root
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 7 Feb 2025 23:22:50 +0000 (23:22 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 10 Feb 2025 18:18:55 +0000 (10:18 -0800)
commita704d39b29dfc21599f644909c0f98bbfa745cb4
tree35c8ac50a735b6bb8a082ee4b0ce4ca22f141d22
parent47d0b0f2bf9d507d5bc9ea8f456cc821829fe21c
os: hide SetFinalizer from users of Root

Currently Root embeds a root and calls SetFinalizer on &r.root. This
sets the finalizer on the outer root, which is visible to users of
os.Root, and thus they can mutate the finalizer attached to it.

This change modifies Root to not embed its inner root, but rather to
refer to it by pointer. This allows us to set the finalizer on this
independent inner object, preventing users of os.Root from changing the
finalizer. This follows the same pattern as os.File's finalizer.

Fixes #71617.

Change-Id: Ibd199bab1b3c877d5e12ef380fd4647b4e10221f
Reviewed-on: https://go-review.googlesource.com/c/go/+/647876
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/os/root.go
src/os/root_noopenat.go
src/os/root_unix.go
src/os/root_windows.go