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

gh-134873: Fix a DOS issue in `posixpath` by Wulian233 · Pull Request #134927 · 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  (1) .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
20 changes: 12 additions & 8 deletions Lib/posixpath.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 @@ -302,6 +302,7 @@ def expandvars(path):
start = b'{'
end = b'}'
environ = getattr(os, 'environb', None)
join = b''.join
else:
if '$' not in path:
return path
Expand All @@ -312,12 +313,16 @@ def expandvars(path):
start = '{'
end = '}'
environ = os.environ
i = 0
join = ''.join

result = []
last = 0
while True:
m = search(path, i)
m = search(path, last)
if not m:
break
i, j = m.span(0)
result.append(path[last:i])
name = m.group(1)
if name.startswith(start) and name.endswith(end):
name = name[1:-1]
Expand All @@ -327,13 +332,12 @@ def expandvars(path):
else:
value = environ[name]
except KeyError:
i = j
result.append(path[i:j])
else:
tail = path[j:]
path = path[:i] + value
i = len(path)
path += tail
return path
result.append(value)
last = j
result.append(path[last:])
return join(result)


# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
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 @@
Fix a DOS vulnerability in :mod:`posixpath` regarding string slicing.

Back | FazBrowse Home | New Git URL