summaryrefslogtreecommitdiffstats
path: root/PC
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-10-04 17:53:43 (GMT)
committerGitHub <noreply@github.com>2019-10-04 17:53:43 (GMT)
commitc02b41b1fb115c87693530ea6a480b2e15460424 (patch)
treedd863614c77112d715aac8277083cdd8d119f905 /PC
parentabd7cd856ba326bd7574135c7d034e98492ab695 (diff)
downloadcpython-c02b41b1fb115c87693530ea6a480b2e15460424.zip
cpython-c02b41b1fb115c87693530ea6a480b2e15460424.tar.gz
cpython-c02b41b1fb115c87693530ea6a480b2e15460424.tar.bz2
bpo-38353: getpath.c: allocates strings on the heap (GH-16585)
* _Py_FindEnvConfigValue() now returns a string allocated by PyMem_RawMalloc(). * calculate_init() now decodes VPATH macro. * Add calculate_open_pyenv() function. * Add substring() and joinpath2() functions. * Fix add_exe_suffix() And a few cleanup changes.
Diffstat (limited to 'PC')
-rw-r--r--PC/getpathp.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/PC/getpathp.c b/PC/getpathp.c
index b17c002..085caf1 100644
--- a/PC/getpathp.c
+++ b/PC/getpathp.c
@@ -752,7 +752,7 @@ calculate_pth_file(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
executable's directory and then in the parent directory.
If found, open it for use when searching for prefixes.
*/
-static void
+static PyStatus
calculate_pyvenv_file(PyCalculatePath *calculate,
wchar_t *argv0_path, size_t argv0_path_len)
{
@@ -775,17 +775,23 @@ calculate_pyvenv_file(PyCalculatePath *calculate,
env_file = _Py_wfopen(filename, L"r");
if (env_file == NULL) {
errno = 0;
- return;
+ return _PyStatus_OK();
}
}
/* Look for a 'home' variable and set argv0_path to it, if found */
- wchar_t home[MAXPATHLEN+1];
- if (_Py_FindEnvConfigValue(env_file, L"home",
- home, Py_ARRAY_LENGTH(home))) {
+ wchar_t *home = NULL;
+ PyStatus status = _Py_FindEnvConfigValue(env_file, L"home", &home);
+ if (_PyStatus_EXCEPTION(status)) {
+ fclose(env_file);
+ return status;
+ }
+ if (home) {
wcscpy_s(argv0_path, argv0_path_len, home);
+ PyMem_RawFree(home);
}
fclose(env_file);
+ return _PyStatus_OK();
}
@@ -1022,7 +1028,11 @@ calculate_path(PyCalculatePath *calculate, _PyPathConfig *pathconfig)
goto done;
}
- calculate_pyvenv_file(calculate, argv0_path, Py_ARRAY_LENGTH(argv0_path));
+ status = calculate_pyvenv_file(calculate,
+ argv0_path, Py_ARRAY_LENGTH(argv0_path));
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
/* Calculate zip archive path from DLL or exe path */
wchar_t zip_path[MAXPATHLEN+1];