summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2023-12-14 15:16:39 (GMT)
committerGitHub <noreply@github.com>2023-12-14 15:16:39 (GMT)
commitfd81afc624402816e3455fd8e932ac7702e4d988 (patch)
tree00e1cd45b60f676d1f3036931c39b8e70ec76b1c /Modules
parent6873555955497e9adbc72fc0e38df5261844aafd (diff)
downloadcpython-fd81afc624402816e3455fd8e932ac7702e4d988.zip
cpython-fd81afc624402816e3455fd8e932ac7702e4d988.tar.gz
cpython-fd81afc624402816e3455fd8e932ac7702e4d988.tar.bz2
gh-86179: Avoid making case-only changes when calculating realpath() during initialization (GH-113077)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/getpath.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c
index 422056b..afa9273 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -506,12 +506,17 @@ done:
HANDLE hFile;
wchar_t resolved[MAXPATHLEN+1];
int len = 0, err;
+ Py_ssize_t pathlen;
PyObject *result;
- wchar_t *path = PyUnicode_AsWideCharString(pathobj, NULL);
+ wchar_t *path = PyUnicode_AsWideCharString(pathobj, &pathlen);
if (!path) {
return NULL;
}
+ if (wcslen(path) != pathlen) {
+ PyErr_SetString(PyExc_ValueError, "path contains embedded nulls");
+ return NULL;
+ }
Py_BEGIN_ALLOW_THREADS
hFile = CreateFileW(path, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
@@ -535,7 +540,11 @@ done:
len -= 4;
}
}
- result = PyUnicode_FromWideChar(p, len);
+ if (CompareStringOrdinal(path, (int)pathlen, p, len, TRUE) == CSTR_EQUAL) {
+ result = Py_NewRef(pathobj);
+ } else {
+ result = PyUnicode_FromWideChar(p, len);
+ }
} else {
result = Py_NewRef(pathobj);
}