Skip to content

Commit 98a91e9

Browse files
zoobamiss-islington
authored andcommitted
gh-151544: Fixes CVE-2026-12003 by removing the fallback to %VPATH%/Modules/Setup.local for discovering sources in getpath.py (GH-151545)
(cherry picked from commit 9e863fa) Co-authored-by: Steve Dower <steve.dower@python.org>
1 parent a7370a9 commit 98a91e9

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

Makefile.pre.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,8 @@ Programs/_bootstrap_python.o: Programs/_bootstrap_python.c $(BOOTSTRAP_HEADERS)
980980
_bootstrap_python: $(LIBRARY_OBJS_OMIT_FROZEN) Programs/_bootstrap_python.o Modules/getpath.o Modules/Setup.local
981981
$(LINKCC) $(PY_LDFLAGS_NOLTO) -o $@ $(LIBRARY_OBJS_OMIT_FROZEN) \
982982
Programs/_bootstrap_python.o Modules/getpath.o $(LIBS) $(MODLIBS) $(SYSLIBS)
983+
# Dummy pybuilddir.txt is needed for _bootstrap_python to be runnable
984+
@echo "none" > ./pybuilddir.txt
983985

984986

985987
############################################################################
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:file:`Modules/Setup.local` is no longer used as a landmark to discover
2+
whether Python is running in a source tree, as it could potentially affect
3+
actual installs. The :file:`pybuilddir.txt` file is now the sole indicator
4+
of running in a source tree.

Modules/getpath.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@
128128
# checked by looking for the BUILDDIR_TXT file, which contains the
129129
# relative path to the platlib dir. The executable_dir value is
130130
# derived from joining the VPATH preprocessor variable to the
131-
# directory containing pybuilddir.txt. If it is not found, the
132-
# BUILD_LANDMARK file is found, which is part of the source tree.
131+
# directory containing pybuilddir.txt.
133132
# prefix is then found by searching up for a file that should only
134133
# exist in the source tree, and the stdlib dir is set to prefix/Lib.
135134

@@ -175,7 +174,6 @@
175174

176175
if os_name == 'posix' or os_name == 'darwin':
177176
BUILDDIR_TXT = 'pybuilddir.txt'
178-
BUILD_LANDMARK = 'Modules/Setup.local'
179177
DEFAULT_PROGRAM_NAME = f'python{VERSION_MAJOR}'
180178
STDLIB_SUBDIR = f'{platlibdir}/python{VERSION_MAJOR}.{VERSION_MINOR}'
181179
STDLIB_LANDMARKS = [f'{STDLIB_SUBDIR}/os.py', f'{STDLIB_SUBDIR}/os.pyc']
@@ -188,7 +186,6 @@
188186

189187
elif os_name == 'nt':
190188
BUILDDIR_TXT = 'pybuilddir.txt'
191-
BUILD_LANDMARK = f'{VPATH}\\Modules\\Setup.local'
192189
DEFAULT_PROGRAM_NAME = f'python'
193190
STDLIB_SUBDIR = 'Lib'
194191
STDLIB_LANDMARKS = [f'{STDLIB_SUBDIR}\\os.py', f'{STDLIB_SUBDIR}\\os.pyc']
@@ -495,13 +492,9 @@ def search_up(prefix, *landmarks, test=isfile):
495492
platstdlib_dir = real_executable_dir
496493
build_prefix = joinpath(real_executable_dir, VPATH)
497494
except (FileNotFoundError, PermissionError):
498-
if isfile(joinpath(real_executable_dir, BUILD_LANDMARK)):
499-
build_prefix = joinpath(real_executable_dir, VPATH)
500-
if os_name == 'nt':
501-
# QUIRK: Windows builds need platstdlib_dir to be the executable
502-
# dir. Normally the builddir marker handles this, but in this
503-
# case we need to correct manually.
504-
platstdlib_dir = real_executable_dir
495+
# We used to check for an alternate landmark here, but now we require
496+
# BUILDDIR_TXT to exist. (gh-151544; CVE-2026-12003)
497+
pass
505498

506499
if build_prefix:
507500
if os_name == 'nt':

0 commit comments

Comments
 (0)