FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-34689: Prevent sysconfig._parse_makefile from expanding $${variables} by lepaperwan · Pull Request #20439 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
29 changes: 20 additions & 9 deletions Lib/sysconfig.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,21 @@ def _parse_makefile(filename, vars=None):
while len(variables) > 0:
for name in tuple(variables):
value = notdone[name]
m1 = _findvar1_rx.search(value)
m2 = _findvar2_rx.search(value)
if m1 and m2:
m = m1 if m1.start() < m2.start() else m2
else:
m = m1 if m1 else m2
m = None
offset = 0
for substr in value.split('$$'):
m1 = _findvar1_rx.search(substr)
m2 = _findvar2_rx.search(substr)
if m1 and m2:
m = m1 if m1.start() < m2.start() else m2
else:
m = m1 if m1 else m2
if m is not None:
break

# Add 2 to account for the $$ which were removed by split('$$')
offset += 2 + len(substr)

if m is not None:
n = m.group(1)
found = True
Expand Down Expand Up @@ -292,11 +301,13 @@ def _parse_makefile(filename, vars=None):
done[n] = item = ""

if found:
after = value[m.end():]
value = value[:m.start()] + item + after
if "$" in after:
after = value[offset + m.end():]
value = value[:offset + m.start()] + \
item.replace('$', '$$') + after
if "$" in after.replace('$$', ''):
notdone[name] = value
else:
value = value.replace('$$', '$')
try:
value = int(value)
except ValueError:
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_sysconfig.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ def test_parse_makefile(self):
print("var5=dollar$$5", file=makefile)
print("var6=${var3}/lib/python3.5/config-$(VAR2)$(var5)"
"-x86_64-linux-gnu", file=makefile)
print("var7=$${ORIGIN}${var5}", file=makefile)
vars = sysconfig._parse_makefile(TESTFN)
self.assertEqual(vars, {
'var1': 'ab42',
Expand All @@ -414,6 +415,7 @@ def test_parse_makefile(self):
'var4': '$/invalid',
'var5': 'dollar$5',
'var6': '42/lib/python3.5/config-b42dollar$5-x86_64-linux-gnu',
'var7': '${ORIGIN}dollar$5',
})


Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Split strings prior to parsing in `sysconfig._parse_makefile` so it doesn't
expand variables formatted as ``$${variable}``.

Back | FazBrowse Home | New Git URL