]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.24] os: hide SetFinalizer from users of Root
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 7 Feb 2025 23:22:50 +0000 (23:22 +0000)
committerMichael Knyszek <mknyszek@google.com>
Mon, 10 Feb 2025 18:48:31 +0000 (10:48 -0800)
commit6d399e9da6090af289aba1f9c4bcc8488387ff9a
tree7d627ff50df3282a2a610a4e2b95596e2f1938e9
parentb7b4c60585f7b341762b70a799e854e991e770ac
[release-branch.go1.24] 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>
(cherry picked from commit a704d39b29dfc21599f644909c0f98bbfa745cb4)
Reviewed-on: https://go-review.googlesource.com/c/go/+/648135
TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/os/root.go
src/os/root_noopenat.go
src/os/root_unix.go
src/os/root_windows.go