diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-19 01:46:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-19 01:46:25 +0100 |
commit | 5f9cf23502febe0eb3bc02e45c7d2bfc79424757 (patch) | |
tree | 66e3e75c52201876c33fb90c9036420687f60dfb /Modules/getpath.c | |
parent | 7b14f0c02ce9d919c503119db190dbca0e703393 (diff) | |
download | cpython-git-5f9cf23502febe0eb3bc02e45c7d2bfc79424757.tar.gz |
bpo-36301: Error if decoding pybuilddir.txt fails (GH-12422)
Python initialization now fails if decoding pybuilddir.txt
configuration file fails at startup.
_PyPathConfig_Calculate() now reports memory allocation failure and
decoding error on decoding pybuilddir.txt content from
UTF-8/surrogateescape.
Diffstat (limited to 'Modules/getpath.c')
-rw-r--r-- | Modules/getpath.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c index 4dafc8b24e..4364317494 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -563,23 +563,27 @@ search_for_exec_prefix(const _PyCoreConfig *core_config, } else { char buf[MAXPATHLEN+1]; - wchar_t *rel_builddir_path; n = fread(buf, 1, MAXPATHLEN, f); buf[n] = '\0'; fclose(f); - rel_builddir_path = _Py_DecodeUTF8_surrogateescape(buf, n); - if (rel_builddir_path) { - wcsncpy(exec_prefix, calculate->argv0_path, MAXPATHLEN); - exec_prefix[MAXPATHLEN] = L'\0'; - err = joinpath(exec_prefix, rel_builddir_path); - PyMem_RawFree(rel_builddir_path ); - if (_Py_INIT_FAILED(err)) { - return err; - } - *found = -1; - return _Py_INIT_OK(); + size_t dec_len; + wchar_t *pybuilddir; + pybuilddir = _Py_DecodeUTF8_surrogateescape(buf, n, &dec_len); + if (!pybuilddir) { + return DECODE_LOCALE_ERR("pybuilddir.txt", dec_len); } + + wcsncpy(exec_prefix, calculate->argv0_path, MAXPATHLEN); + exec_prefix[MAXPATHLEN] = L'\0'; + err = joinpath(exec_prefix, pybuilddir); + PyMem_RawFree(pybuilddir ); + if (_Py_INIT_FAILED(err)) { + return err; + } + + *found = -1; + return _Py_INIT_OK(); } } |