summaryrefslogtreecommitdiff
path: root/PC
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-09-30 14:49:34 +0200
committerGitHub <noreply@github.com>2019-09-30 14:49:34 +0200
commitdec39716ca93ee2e8d9b94915ece33014eb58e9e (patch)
treefe3ddadba7989368b2e149c5e57331af8fb6d36b /PC
parent89f8177dcfdbcf17c85bb6998c946c9f42bf6e27 (diff)
downloadcpython-git-dec39716ca93ee2e8d9b94915ece33014eb58e9e.tar.gz
bpo-38322: Fix gotlandmark() of PC/getpathp.c (GH-16489)
Write the filename into a temporary buffer instead of reusing prefix. The problem is that join() modifies prefix inplace. If prefix is not normalized, join() can make prefix shorter and so gotlandmark() does modify prefix instead of returning it unmodified.
Diffstat (limited to 'PC')
-rw-r--r--PC/getpathp.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/PC/getpathp.c b/PC/getpathp.c
index 8bac592aef..04f24d986f 100644
--- a/PC/getpathp.c
+++ b/PC/getpathp.c
@@ -315,15 +315,13 @@ canonicalize(wchar_t *buffer, const wchar_t *path)
'prefix' is null terminated in bounds. join() ensures
'landmark' can not overflow prefix if too long. */
static int
-gotlandmark(wchar_t *prefix, const wchar_t *landmark)
+gotlandmark(const wchar_t *prefix, const wchar_t *landmark)
{
- int ok;
- Py_ssize_t n = wcsnlen_s(prefix, MAXPATHLEN);
-
- join(prefix, landmark);
- ok = ismodule(prefix, FALSE);
- prefix[n] = '\0';
- return ok;
+ wchar_t filename[MAXPATHLEN+1];
+ memset(filename, 0, sizeof(filename));
+ wcscpy_s(filename, Py_ARRAY_LENGTH(filename), prefix);
+ join(filename, landmark);
+ return ismodule(filename, FALSE);
}