mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
89f8177dcf
commit
dec39716ca
|
@ -315,15 +315,13 @@ canonicalize(wchar_t *buffer, const wchar_t *path)
|
||||||
'prefix' is null terminated in bounds. join() ensures
|
'prefix' is null terminated in bounds. join() ensures
|
||||||
'landmark' can not overflow prefix if too long. */
|
'landmark' can not overflow prefix if too long. */
|
||||||
static int
|
static int
|
||||||
gotlandmark(wchar_t *prefix, const wchar_t *landmark)
|
gotlandmark(const wchar_t *prefix, const wchar_t *landmark)
|
||||||
{
|
{
|
||||||
int ok;
|
wchar_t filename[MAXPATHLEN+1];
|
||||||
Py_ssize_t n = wcsnlen_s(prefix, MAXPATHLEN);
|
memset(filename, 0, sizeof(filename));
|
||||||
|
wcscpy_s(filename, Py_ARRAY_LENGTH(filename), prefix);
|
||||||
join(prefix, landmark);
|
join(filename, landmark);
|
||||||
ok = ismodule(prefix, FALSE);
|
return ismodule(filename, FALSE);
|
||||||
prefix[n] = '\0';
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue