mirror of https://github.com/python/cpython.git
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
_Py_char2wchar(), instead of L"" VAR hack, to escape undecodable bytes using the surrogateescape error handler.
This commit is contained in:
parent
d5af0a5df0
commit
ae4836df6d
|
@ -263,7 +263,7 @@ absolutize(wchar_t *path)
|
||||||
bytes long.
|
bytes long.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
search_for_prefix(wchar_t *argv0_path, wchar_t *home)
|
search_for_prefix(wchar_t *argv0_path, wchar_t *home, wchar_t *_prefix)
|
||||||
{
|
{
|
||||||
size_t n;
|
size_t n;
|
||||||
wchar_t *vpath;
|
wchar_t *vpath;
|
||||||
|
@ -310,7 +310,7 @@ search_for_prefix(wchar_t *argv0_path, wchar_t *home)
|
||||||
} while (prefix[0]);
|
} while (prefix[0]);
|
||||||
|
|
||||||
/* Look at configure's PREFIX */
|
/* Look at configure's PREFIX */
|
||||||
wcsncpy(prefix, L"" PREFIX, MAXPATHLEN);
|
wcsncpy(prefix, _prefix, MAXPATHLEN);
|
||||||
joinpath(prefix, lib_python);
|
joinpath(prefix, lib_python);
|
||||||
joinpath(prefix, LANDMARK);
|
joinpath(prefix, LANDMARK);
|
||||||
if (ismodule(prefix))
|
if (ismodule(prefix))
|
||||||
|
@ -325,7 +325,7 @@ search_for_prefix(wchar_t *argv0_path, wchar_t *home)
|
||||||
MAXPATHLEN bytes long.
|
MAXPATHLEN bytes long.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home)
|
search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home, wchar_t *_exec_prefix)
|
||||||
{
|
{
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home)
|
||||||
} while (exec_prefix[0]);
|
} while (exec_prefix[0]);
|
||||||
|
|
||||||
/* Look at configure's EXEC_PREFIX */
|
/* Look at configure's EXEC_PREFIX */
|
||||||
wcsncpy(exec_prefix, L"" EXEC_PREFIX, MAXPATHLEN);
|
wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN);
|
||||||
joinpath(exec_prefix, lib_python);
|
joinpath(exec_prefix, lib_python);
|
||||||
joinpath(exec_prefix, L"lib-dynload");
|
joinpath(exec_prefix, L"lib-dynload");
|
||||||
if (isdir(exec_prefix))
|
if (isdir(exec_prefix))
|
||||||
|
@ -397,7 +397,6 @@ search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
calculate_path(void)
|
calculate_path(void)
|
||||||
{
|
{
|
||||||
|
@ -405,7 +404,6 @@ calculate_path(void)
|
||||||
|
|
||||||
static wchar_t delimiter[2] = {DELIM, '\0'};
|
static wchar_t delimiter[2] = {DELIM, '\0'};
|
||||||
static wchar_t separator[2] = {SEP, '\0'};
|
static wchar_t separator[2] = {SEP, '\0'};
|
||||||
wchar_t *pythonpath = L"" PYTHONPATH;
|
|
||||||
char *_rtpypath = Py_GETENV("PYTHONPATH"); /* XXX use wide version on Windows */
|
char *_rtpypath = Py_GETENV("PYTHONPATH"); /* XXX use wide version on Windows */
|
||||||
wchar_t rtpypath[MAXPATHLEN+1];
|
wchar_t rtpypath[MAXPATHLEN+1];
|
||||||
wchar_t *home = Py_GetPythonHome();
|
wchar_t *home = Py_GetPythonHome();
|
||||||
|
@ -419,7 +417,7 @@ calculate_path(void)
|
||||||
wchar_t *buf;
|
wchar_t *buf;
|
||||||
size_t bufsz;
|
size_t bufsz;
|
||||||
size_t prefixsz;
|
size_t prefixsz;
|
||||||
wchar_t *defpath = pythonpath;
|
wchar_t *defpath;
|
||||||
#ifdef WITH_NEXT_FRAMEWORK
|
#ifdef WITH_NEXT_FRAMEWORK
|
||||||
NSModule pythonModule;
|
NSModule pythonModule;
|
||||||
#endif
|
#endif
|
||||||
|
@ -429,8 +427,19 @@ calculate_path(void)
|
||||||
#else
|
#else
|
||||||
unsigned long nsexeclength = MAXPATHLEN;
|
unsigned long nsexeclength = MAXPATHLEN;
|
||||||
#endif
|
#endif
|
||||||
char execpath[MAXPATHLEN+1];
|
char execpath[MAXPATHLEN+1];
|
||||||
#endif
|
#endif
|
||||||
|
wchar_t *_pythonpath, *_prefix, *_exec_prefix;
|
||||||
|
|
||||||
|
_pythonpath = _Py_char2wchar(PYTHONPATH, NULL);
|
||||||
|
_prefix = _Py_char2wchar(PREFIX, NULL);
|
||||||
|
_exec_prefix = _Py_char2wchar(EXEC_PREFIX, NULL);
|
||||||
|
|
||||||
|
if (!_pythonpath || !_prefix || !_exec_prefix) {
|
||||||
|
Py_FatalError(
|
||||||
|
"Unable to decode path variables in getpath.c: "
|
||||||
|
"memory error");
|
||||||
|
}
|
||||||
|
|
||||||
if (_path) {
|
if (_path) {
|
||||||
path_buffer = _Py_char2wchar(_path, NULL);
|
path_buffer = _Py_char2wchar(_path, NULL);
|
||||||
|
@ -555,11 +564,11 @@ calculate_path(void)
|
||||||
MAXPATHLEN bytes long.
|
MAXPATHLEN bytes long.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!(pfound = search_for_prefix(argv0_path, home))) {
|
if (!(pfound = search_for_prefix(argv0_path, home, _prefix))) {
|
||||||
if (!Py_FrozenFlag)
|
if (!Py_FrozenFlag)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Could not find platform independent libraries <prefix>\n");
|
"Could not find platform independent libraries <prefix>\n");
|
||||||
wcsncpy(prefix, L"" PREFIX, MAXPATHLEN);
|
wcsncpy(prefix, _prefix, MAXPATHLEN);
|
||||||
joinpath(prefix, lib_python);
|
joinpath(prefix, lib_python);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -572,17 +581,17 @@ calculate_path(void)
|
||||||
reduce(zip_path);
|
reduce(zip_path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
wcsncpy(zip_path, L"" PREFIX, MAXPATHLEN);
|
wcsncpy(zip_path, _prefix, MAXPATHLEN);
|
||||||
joinpath(zip_path, L"lib/python00.zip");
|
joinpath(zip_path, L"lib/python00.zip");
|
||||||
bufsz = wcslen(zip_path); /* Replace "00" with version */
|
bufsz = wcslen(zip_path); /* Replace "00" with version */
|
||||||
zip_path[bufsz - 6] = VERSION[0];
|
zip_path[bufsz - 6] = VERSION[0];
|
||||||
zip_path[bufsz - 5] = VERSION[2];
|
zip_path[bufsz - 5] = VERSION[2];
|
||||||
|
|
||||||
if (!(efound = search_for_exec_prefix(argv0_path, home))) {
|
if (!(efound = search_for_exec_prefix(argv0_path, home, _exec_prefix))) {
|
||||||
if (!Py_FrozenFlag)
|
if (!Py_FrozenFlag)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Could not find platform dependent libraries <exec_prefix>\n");
|
"Could not find platform dependent libraries <exec_prefix>\n");
|
||||||
wcsncpy(exec_prefix, L"" EXEC_PREFIX, MAXPATHLEN);
|
wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN);
|
||||||
joinpath(exec_prefix, L"lib/lib-dynload");
|
joinpath(exec_prefix, L"lib/lib-dynload");
|
||||||
}
|
}
|
||||||
/* If we found EXEC_PREFIX do *not* reduce it! (Yet.) */
|
/* If we found EXEC_PREFIX do *not* reduce it! (Yet.) */
|
||||||
|
@ -604,8 +613,8 @@ calculate_path(void)
|
||||||
bufsz += wcslen(rtpypath) + 1;
|
bufsz += wcslen(rtpypath) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defpath = _pythonpath;
|
||||||
prefixsz = wcslen(prefix) + 1;
|
prefixsz = wcslen(prefix) + 1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
wchar_t *delim = wcschr(defpath, DELIM);
|
wchar_t *delim = wcschr(defpath, DELIM);
|
||||||
|
|
||||||
|
@ -650,7 +659,7 @@ calculate_path(void)
|
||||||
/* Next goes merge of compile-time $PYTHONPATH with
|
/* Next goes merge of compile-time $PYTHONPATH with
|
||||||
* dynamically located prefix.
|
* dynamically located prefix.
|
||||||
*/
|
*/
|
||||||
defpath = pythonpath;
|
defpath = _pythonpath;
|
||||||
while (1) {
|
while (1) {
|
||||||
wchar_t *delim = wcschr(defpath, DELIM);
|
wchar_t *delim = wcschr(defpath, DELIM);
|
||||||
|
|
||||||
|
@ -694,7 +703,7 @@ calculate_path(void)
|
||||||
wcscpy(prefix, separator);
|
wcscpy(prefix, separator);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
wcsncpy(prefix, L"" PREFIX, MAXPATHLEN);
|
wcsncpy(prefix, _prefix, MAXPATHLEN);
|
||||||
|
|
||||||
if (efound > 0) {
|
if (efound > 0) {
|
||||||
reduce(exec_prefix);
|
reduce(exec_prefix);
|
||||||
|
@ -704,7 +713,11 @@ calculate_path(void)
|
||||||
wcscpy(exec_prefix, separator);
|
wcscpy(exec_prefix, separator);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
wcsncpy(exec_prefix, L"" EXEC_PREFIX, MAXPATHLEN);
|
wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN);
|
||||||
|
|
||||||
|
PyMem_Free(_pythonpath);
|
||||||
|
PyMem_Free(_prefix);
|
||||||
|
PyMem_Free(_exec_prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue