Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 18c4ba9

Browse files
authored
bpo-38322: Fix gotlandmark() of PC/getpathp.c (pythonGH-16490)
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.
1 parent 81f6b03 commit 18c4ba9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

PC/getpathp.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,13 @@ canonicalize(wchar_t *buffer, const wchar_t *path)
315315
'prefix' is null terminated in bounds. join() ensures
316316
'landmark' can not overflow prefix if too long. */
317317
static int
318-
gotlandmark(wchar_t *prefix, const wchar_t *landmark)
318+
gotlandmark(const wchar_t *prefix, const wchar_t *landmark)
319319
{
320-
int ok;
321-
Py_ssize_t n = wcsnlen_s(prefix, MAXPATHLEN);
322-
323-
join(prefix, landmark);
324-
ok = ismodule(prefix, FALSE);
325-
prefix[n] = '\0';
326-
return ok;
320+
wchar_t filename[MAXPATHLEN+1];
321+
memset(filename, 0, sizeof(filename));
322+
wcscpy_s(filename, Py_ARRAY_LENGTH(filename), prefix);
323+
join(filename, landmark);
324+
return ismodule(filename, FALSE);
327325
}
328326

329327

0 commit comments

Comments
 (0)