This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Coverity scan: Modules/getpath.c. "calculate_open_pyenv" allocates memory that is stored into "env_file".
Type: Stage: resolved
Components: Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cstratak, miss-islington, petr.viktorin, vstinner
Priority: normal Keywords: patch

Created on 2021-06-02 13:39 by cstratak, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26486 merged cstratak, 2021-06-02 13:44
PR 26495 merged miss-islington, 2021-06-02 23:26
PR 26496 merged miss-islington, 2021-06-02 23:27
Messages (7)
msg394906 - (view) Author: Charalampos Stratakis (cstratak) * Date: 2021-06-02 13:39
This is an issue as it seems with coverity as it's an error case where the file was not actually opened. This warning can be silenced and the code be made more explicit by adding an assertion.

Python-3.9.1/Modules/getpath.c:1264: alloc_arg: "calculate_open_pyenv" allocates memory that is stored into "env_file".
Python-3.9.1/Modules/getpath.c:1266: leaked_storage: Variable "env_file" going out of scope leaks the storage it points to.
# 1264|       status = calculate_open_pyenv(calculate, &env_file);
# 1265|       if (_PyStatus_EXCEPTION(status)) {
# 1266|->         return status;
# 1267|       }
# 1268|       if (env_file == NULL) {
msg394907 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2021-06-02 13:49
+1, for adding the assertion. It's not trivial to see that env_file must be NULL here, even for me (a human).
msg394908 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-06-02 13:53
I still plan to rewrite getpath.c C file in Python: https://bugs.python.org/issue42260 But it's an incompatible change and a low priority for me.
msg394917 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2021-06-02 14:54
New changeset bdb56902a3bfe12b10f85a941d5dd0eae739f1a8 by stratakis in branch 'main':
bpo-44285: getpath.c: Assert that env_file is NULL during an error check (GH-26486)
https://github.com/python/cpython/commit/bdb56902a3bfe12b10f85a941d5dd0eae739f1a8
msg394956 - (view) Author: miss-islington (miss-islington) Date: 2021-06-02 23:50
New changeset 0e9af8cae314e4b0e770fe48d5f7b5f540c0b257 by Miss Islington (bot) in branch '3.10':
bpo-44285: getpath.c: Assert that env_file is NULL during an error check (GH-26486)
https://github.com/python/cpython/commit/0e9af8cae314e4b0e770fe48d5f7b5f540c0b257
msg394957 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-06-02 23:50
New changeset 85b587a38dcf5d0ef1e275510001e22425d65977 by Miss Islington (bot) in branch '3.9':
bpo-44285: getpath.c: Assert that env_file is NULL during an error check (GH-26486) (GH-26496)
https://github.com/python/cpython/commit/85b587a38dcf5d0ef1e275510001e22425d65977
msg394958 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-06-02 23:51
Thanks Charalampos, it's now fixed in 3.9, 3.10 and main branches.
History
Date User Action Args
2022-04-11 14:59:46adminsetgithub: 88451
2021-06-02 23:51:26vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg394958

stage: patch review -> resolved
2021-06-02 23:50:59vstinnersetmessages: + msg394957
2021-06-02 23:50:42miss-islingtonsetmessages: + msg394956
2021-06-02 23:27:01miss-islingtonsetpull_requests: + pull_request25092
2021-06-02 23:26:55miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25091
2021-06-02 14:54:58petr.viktorinsetmessages: + msg394917
2021-06-02 13:53:07vstinnersetnosy: + vstinner

messages: + msg394908
versions: - Python 3.8
2021-06-02 13:49:10petr.viktorinsetnosy: + petr.viktorin
messages: + msg394907
2021-06-02 13:44:53cstrataksetkeywords: + patch
stage: patch review
pull_requests: + pull_request25082
2021-06-02 13:39:39cstratakcreate