rehash: fix race condition in landlock writability check (#3483)

This commit is contained in:
Yo Takezawa 2026-06-27 03:04:33 +09:00 committed by GitHub
parent ebd788d08c
commit 3974647f0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -28,7 +28,9 @@ acquire_lock() {
# So check for writablity by trying to write to a different file, # So check for writablity by trying to write to a different file,
# in a way that taxes the usual use case as little as possible. # in a way that taxes the usual use case as little as possible.
if [[ -z $tested_for_other_write_errors ]]; then if [[ -z $tested_for_other_write_errors ]]; then
( t="$(TMPDIR="$SHIM_PATH" mktemp)" && rm "$t" ) \ # if lots of (50+) rehashes run concurrently, another concurrent rehash
# may delete the temporary file in remove_*_shims() before we do so
( t="$(TMPDIR="$SHIM_PATH" mktemp)" && rm -f "$t" ) \
&& tested_for_other_write_errors=1 \ && tested_for_other_write_errors=1 \
|| { echo "pyenv: cannot rehash: $SHIM_PATH isn't writable" >&2 || { echo "pyenv: cannot rehash: $SHIM_PATH isn't writable" >&2
set +o noclobber set +o noclobber