Skip to content

Commit 68b131d

Browse files
authored
[3.6] closes bpo-22140: Prevent double substitution of prefix in python-config.sh (GH-3769) (#3793)
Fix the logic in python-config.sh to avoid attempting to substitute prefix in a variable that might have already been subject to substitution. This e.g. happened if @exec_prefix@ was defined as "${prefix}" (which is the default of the configure script) -- in which case the exec_prefix_build variable was initialized with already-subtituted prefix, and then another round of substitution was performed which might have resulted in duplicate prefix. To avoid that, rename the variables so that the variables matching likely configure names (prefix, exec_prefix) retain their original values and a '_real' suffix is used for the real values of prefix. Furthermore, replace the unnecessary prefix and exec_prefix substitutions with direct prefix_real references since the sed always replaced the whole string anyway by design. (cherry picked from commit 14086cf)
1 parent 084f80b commit 68b131d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevent double substitution of prefix in python-config.sh.

Misc/python-config.sh.in

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ installed_prefix ()
2424
echo $RESULT
2525
}
2626

27-
prefix_build="@prefix@"
2827
prefix_real=$(installed_prefix "$0")
2928

3029
# Use sed to fix paths from their built-to locations to their installed-to
31-
# locations.
32-
prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#")
33-
exec_prefix_build="@exec_prefix@"
34-
exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#")
35-
includedir=$(echo "@includedir@" | sed "s#$prefix_build#$prefix_real#")
36-
libdir=$(echo "@libdir@" | sed "s#$prefix_build#$prefix_real#")
37-
CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix_build#$prefix_real#")
30+
# locations. Keep prefix & exec_prefix using their original values in case
31+
# they are referenced in other configure variables, to prevent double
32+
# substitution, issue #22140.
33+
prefix="@prefix@"
34+
exec_prefix="@exec_prefix@"
35+
exec_prefix_real=${prefix_real}
36+
includedir=$(echo "@includedir@" | sed "s#$prefix#$prefix_real#")
37+
libdir=$(echo "@libdir@" | sed "s#$prefix#$prefix_real#")
38+
CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix#$prefix_real#")
3839
VERSION="@VERSION@"
3940
LIBM="@LIBM@"
4041
LIBC="@LIBC@"
@@ -47,8 +48,8 @@ LINKFORSHARED="@LINKFORSHARED@"
4748
OPT="@OPT@"
4849
PY_ENABLE_SHARED="@PY_ENABLE_SHARED@"
4950
LDVERSION="@LDVERSION@"
50-
LIBDEST=${prefix}/lib/python${VERSION}
51-
LIBPL=$(echo "@LIBPL@" | sed "s#$prefix_build#$prefix_real#")
51+
LIBDEST=${prefix_real}/lib/python${VERSION}
52+
LIBPL=$(echo "@LIBPL@" | sed "s#$prefix#$prefix_real#")
5253
SO="@EXT_SUFFIX@"
5354
PYTHONFRAMEWORK="@PYTHONFRAMEWORK@"
5455
INCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"
@@ -73,10 +74,10 @@ for ARG in "$@"
7374
do
7475
case "$ARG" in
7576
--prefix)
76-
echo "$prefix"
77+
echo "$prefix_real"
7778
;;
7879
--exec-prefix)
79-
echo "$exec_prefix"
80+
echo "$exec_prefix_real"
8081
;;
8182
--includes)
8283
echo "$INCDIR $PLATINCDIR"

0 commit comments

Comments
 (0)