Skip to content

[3.8] bpo-38081: Fixes ntpath.realpath('NUL') (GH-15899) #15903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,10 @@ def _readlink_deep(path, seen=None):
try:
path = _nt_readlink(path)
except OSError as ex:
# Stop on file (2) or directory (3) not found, or
# paths that are not reparse points (4390)
if ex.winerror in (2, 3, 4390):
# Stop on incorrect function (1), file (2) or
# directory (3) not found, or paths that are
# not reparse points (4390)
if ex.winerror in (1, 2, 3, 4390):
break
raise
except ValueError:
Expand All @@ -553,9 +554,9 @@ def _getfinalpathname_nonstrict(path):
except OSError:
pass

# Allow file (2) or directory (3) not found, invalid syntax (123),
# and symlinks that cannot be followed (1921)
allowed_winerror = 2, 3, 123, 1921
# Allow file (2) or directory (3) not found, incorrect parameter (87),
# invalid syntax (123), and symlinks that cannot be followed (1921)
allowed_winerror = 2, 3, 87, 123, 1921

# Non-strict algorithm is to find as much of the target directory
# as we can and join the rest.
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ def test_realpath_symlink_prefix(self):
self.assertPathEqual(ntpath.realpath("\\\\?\\" + ABSTFN + "3.link"),
"\\\\?\\" + ABSTFN + "3.")

@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
def test_realpath_nul(self):
tester("ntpath.realpath('NUL')", r'\\.\NUL')

def test_expandvars(self):
with support.EnvironmentVarGuard() as env:
env.clear()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent error calling :func:`os.path.realpath` on ``'NUL'``.