mirror of
https://github.com/python/cpython
synced 2024-10-14 09:01:41 +00:00
bpo-45375: Fix assertion failure due to searching for stdlib in unnormalised paths (GH-28735)
This commit is contained in:
parent
de4052fe06
commit
5146877623
|
@ -0,0 +1,2 @@
|
||||||
|
Fixes an assertion failure due to searching for the standard library in
|
||||||
|
unnormalised paths.
|
|
@ -265,7 +265,21 @@ canonicalize(wchar_t *buffer, const wchar_t *path)
|
||||||
return _PyStatus_NO_MEMORY();
|
return _PyStatus_NO_MEMORY();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAILED(PathCchCanonicalizeEx(buffer, MAXPATHLEN + 1, path, 0))) {
|
if (PathIsRelativeW(path)) {
|
||||||
|
wchar_t buff[MAXPATHLEN];
|
||||||
|
if (!GetCurrentDirectoryW(MAXPATHLEN, buff)) {
|
||||||
|
return _PyStatus_ERR("unable to find current working directory");
|
||||||
|
}
|
||||||
|
if (FAILED(PathCchCombineEx(buff, MAXPATHLEN + 1, buff, path, PATHCCH_ALLOW_LONG_PATHS))) {
|
||||||
|
return INIT_ERR_BUFFER_OVERFLOW();
|
||||||
|
}
|
||||||
|
if (FAILED(PathCchCanonicalizeEx(buffer, MAXPATHLEN + 1, buff, PATHCCH_ALLOW_LONG_PATHS))) {
|
||||||
|
return INIT_ERR_BUFFER_OVERFLOW();
|
||||||
|
}
|
||||||
|
return _PyStatus_OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FAILED(PathCchCanonicalizeEx(buffer, MAXPATHLEN + 1, path, PATHCCH_ALLOW_LONG_PATHS))) {
|
||||||
return INIT_ERR_BUFFER_OVERFLOW();
|
return INIT_ERR_BUFFER_OVERFLOW();
|
||||||
}
|
}
|
||||||
return _PyStatus_OK();
|
return _PyStatus_OK();
|
||||||
|
@ -291,6 +305,9 @@ search_for_prefix(wchar_t *prefix, const wchar_t *argv0_path)
|
||||||
/* Search from argv0_path, until LANDMARK is found.
|
/* Search from argv0_path, until LANDMARK is found.
|
||||||
We guarantee 'prefix' is null terminated in bounds. */
|
We guarantee 'prefix' is null terminated in bounds. */
|
||||||
wcscpy_s(prefix, MAXPATHLEN+1, argv0_path);
|
wcscpy_s(prefix, MAXPATHLEN+1, argv0_path);
|
||||||
|
if (!prefix[0]) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
wchar_t stdlibdir[MAXPATHLEN+1];
|
wchar_t stdlibdir[MAXPATHLEN+1];
|
||||||
wcscpy_s(stdlibdir, Py_ARRAY_LENGTH(stdlibdir), prefix);
|
wcscpy_s(stdlibdir, Py_ARRAY_LENGTH(stdlibdir), prefix);
|
||||||
/* We initialize with the longest possible path, in case it doesn't fit.
|
/* We initialize with the longest possible path, in case it doesn't fit.
|
||||||
|
@ -925,6 +942,7 @@ calculate_module_search_path(PyCalculatePath *calculate,
|
||||||
the parent of that.
|
the parent of that.
|
||||||
*/
|
*/
|
||||||
if (prefix[0] == L'\0') {
|
if (prefix[0] == L'\0') {
|
||||||
|
PyStatus status;
|
||||||
wchar_t lookBuf[MAXPATHLEN+1];
|
wchar_t lookBuf[MAXPATHLEN+1];
|
||||||
const wchar_t *look = buf - 1; /* 'buf' is at the end of the buffer */
|
const wchar_t *look = buf - 1; /* 'buf' is at the end of the buffer */
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -939,6 +957,10 @@ calculate_module_search_path(PyCalculatePath *calculate,
|
||||||
nchars = lookEnd-look;
|
nchars = lookEnd-look;
|
||||||
wcsncpy(lookBuf, look+1, nchars);
|
wcsncpy(lookBuf, look+1, nchars);
|
||||||
lookBuf[nchars] = L'\0';
|
lookBuf[nchars] = L'\0';
|
||||||
|
status = canonicalize(lookBuf, lookBuf);
|
||||||
|
if (_PyStatus_EXCEPTION(status)) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
/* Up one level to the parent */
|
/* Up one level to the parent */
|
||||||
reduce(lookBuf);
|
reduce(lookBuf);
|
||||||
if (search_for_prefix(prefix, lookBuf)) {
|
if (search_for_prefix(prefix, lookBuf)) {
|
||||||
|
|
|
@ -104,7 +104,9 @@
|
||||||
Condition="($(Platform) == 'Win32' or $(Platform) == 'x64') and
|
Condition="($(Platform) == 'Win32' or $(Platform) == 'x64') and
|
||||||
$(Configuration) != 'PGInstrument' and $(Configuration) != 'PGUpdate'">
|
$(Configuration) != 'PGInstrument' and $(Configuration) != 'PGUpdate'">
|
||||||
<Message Text="Regenerate @(_TestFrozenOutputs->'%(Filename)%(Extension)', ' ')" Importance="high" />
|
<Message Text="Regenerate @(_TestFrozenOutputs->'%(Filename)%(Extension)', ' ')" Importance="high" />
|
||||||
<Exec Command="$(PythonExe) Programs\freeze_test_frozenmain.py Programs/test_frozenmain.h"
|
<Exec Command='setlocal
|
||||||
|
set PYTHONPATH=$(PySourcePath)Lib
|
||||||
|
"$(PythonExe)" Programs\freeze_test_frozenmain.py Programs\test_frozenmain.h'
|
||||||
WorkingDirectory="$(PySourcePath)" />
|
WorkingDirectory="$(PySourcePath)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue