Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dec3971

Browse files
authored
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.
1 parent 89f8177 commit dec3971

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

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)