summaryrefslogtreecommitdiffstats
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-08-22 14:35:16 (GMT)
committerGitHub <noreply@github.com>2023-08-22 14:35:16 (GMT)
commit8927cf0200e56ebf74ed43f8c3fd724cd699ec22 (patch)
treee96ec98066c50aa34c4a3fa0412c16d4e484982b /Lib/ntpath.py
parentd22ac0c6052c4e568c316ce3ce194fdf86d9af87 (diff)
downloadcpython-8927cf0200e56ebf74ed43f8c3fd724cd699ec22.zip
cpython-8927cf0200e56ebf74ed43f8c3fd724cd699ec22.tar.gz
cpython-8927cf0200e56ebf74ed43f8c3fd724cd699ec22.tar.bz2
[3.11] gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls (GH-108248)
gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls (GH-108248) --------- (cherry picked from commit de33b5c662ea8d35d81ed857c6a39e34ab94c510) Co-authored-by: Steve Dower <steve.dower@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 0444b0f..0246419 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -695,6 +695,14 @@ else:
try:
path = _getfinalpathname(path)
initial_winerror = 0
+ except ValueError as ex:
+ # gh-106242: Raised for embedded null characters
+ # In strict mode, we convert into an OSError.
+ # Non-strict mode returns the path as-is, since we've already
+ # made it absolute.
+ if strict:
+ raise OSError(str(ex)) from None
+ path = normpath(path)
except OSError as ex:
if strict:
raise
@@ -714,6 +722,10 @@ else:
try:
if _getfinalpathname(spath) == path:
path = spath
+ except ValueError as ex:
+ # Unexpected, as an invalid path should not have gained a prefix
+ # at any point, but we ignore this error just in case.
+ pass
except OSError as ex:
# If the path does not exist and originally did not exist, then
# strip the prefix anyway.