diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-20 00:30:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-20 00:30:45 +0100 |
commit | f7959a9fe7e7e316899c60251e29390c4ed0307a (patch) | |
tree | 5e9600d8bbe31dbfe6023c660d4d140d5b892e7a /Python | |
parent | 935250d6f3ac7ba91e1ea8e6ca63aaf7f605e291 (diff) | |
download | cpython-git-f7959a9fe7e7e316899c60251e29390c4ed0307a.tar.gz |
bpo-36236: Handle removed cwd at Python init (GH-12450)
At Python initialization, the current directory is no longer
prepended to sys.path if it has been removed.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pathconfig.c | 13 | ||||
-rw-r--r-- | Python/sysmodule.c | 5 |
2 files changed, 13 insertions, 5 deletions
diff --git a/Python/pathconfig.c b/Python/pathconfig.c index aacc5f5a5f..3a43143135 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -278,8 +278,8 @@ Py_GetProgramName(void) } /* Compute argv[0] which will be prepended to sys.argv */ -PyObject* -_PyPathConfig_ComputeArgv0(int argc, wchar_t **argv) +int +_PyPathConfig_ComputeArgv0(int argc, wchar_t **argv, PyObject **argv0_p) { wchar_t *argv0; wchar_t *p = NULL; @@ -297,6 +297,8 @@ _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv) wchar_t fullpath[MAX_PATH]; #endif + assert(*argv0_p == NULL); + argv0 = argv[0]; if (argc > 0 && argv0 != NULL) { have_module_arg = (wcscmp(argv0, L"-m") == 0); @@ -305,7 +307,9 @@ _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv) if (have_module_arg) { #if defined(HAVE_REALPATH) || defined(MS_WINDOWS) - _Py_wgetcwd(fullpath, Py_ARRAY_LENGTH(fullpath)); + if (!_Py_wgetcwd(fullpath, Py_ARRAY_LENGTH(fullpath))) { + return 0; + } argv0 = fullpath; n = wcslen(argv0); #else @@ -384,7 +388,8 @@ _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv) } #endif /* All others */ - return PyUnicode_FromWideChar(argv0, n); + *argv0_p = PyUnicode_FromWideChar(argv0, n); + return 1; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index cdc2edf038..c01a04e6c0 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2615,7 +2615,10 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) if (updatepath) { /* If argv[0] is not '-c' nor '-m', prepend argv[0] to sys.path. If argv[0] is a symlink, use the real path. */ - PyObject *argv0 = _PyPathConfig_ComputeArgv0(argc, argv); + PyObject *argv0 = NULL; + if (!_PyPathConfig_ComputeArgv0(argc, argv, &argv0)) { + return; + } if (argv0 == NULL) { Py_FatalError("can't compute path0 from argv"); } |