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: Add error checks to PyInit_pyexpat()
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, christian.heimes, eli.bendersky, iritkatriel, scoder
Priority: normal Keywords: patch

Created on 2015-04-19 19:33 by christian.heimes, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pyexpat.patch christian.heimes, 2015-04-19 19:33 review
Messages (3)
msg241555 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2015-04-19 19:33
Similar to #24011 and #24010 the pyexpat module's init function fails to check some return values for NULL. The patch doesn't include proper reference cleanups as most of the other parts of PyInit_pyexpat() don't cleanup on error, too.

CID 982779 (#2 of 2): Dereference null return value (NULL_RETURNS)
dereference: Dereferencing a pointer that might be null sys_modules when calling PyDict_SetItem

CID 982240 (#2 of 2): Unchecked return value (CHECKED_RETURN)
check_return: Calling PyDict_SetItem without checking return value (as is done elsewhere 158 out of 174 times)
msg323667 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-08-17 20:35
Some parts of the patch have already been applied into master:

* PySys_GetObject(): https://github.com/python/cpython/commit/7a5457b6878db61910c81017d10579edb7c91512

* PyDict_SetItem(): https://github.com/python/cpython/commit/3f9eee6eb4b25fe1926eaa5f00e02344b126f54d#diff-cc8b737f9996c36521d5b9db5ea1a032

The only remaining part is about PyModule_AddObject(), but there are already many usages of PyModule_AddObject() without doing any error checking, so I suggest closing this as 'outdated'.
msg408325 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-12-11 17:54
This is all sorted now:

iritkatriel@Irits-MBP cpython % grep "PyModule_AddObject(" Modules/pyexpat.c 
    if (PyModule_AddObject(mod, name, submodule) < 0) {
    if (PyModule_AddObject(errors_module, "codes", codes_dict) < 0) {
    if (PyModule_AddObject(errors_module, "messages", rev_codes_dict) < 0) {
    if (PyModule_AddObject(mod, "features", list) < 0) {
        if (PyModule_AddObject(mod, "version_info", versionInfo) < 0) {
    if (PyModule_AddObject(mod, "expat_CAPI", capi_object) < 0) {
iritkatriel@Irits-MBP cpython % grep "PyDict_SetItem(" Modules/pyexpat.c
            PyDict_SetItem(self->intern, result, result) == 0)
            else if (PyDict_SetItem(container, n, v)) {
    int res = PyDict_SetItem(rev_codes_dict, num, str);
iritkatriel@Irits-MBP cpython % grep "PySys_GetObject(" Modules/pyexpat.c
iritkatriel@Irits-MBP cpython %
History
Date User Action Args
2022-04-11 14:58:15adminsetgithub: 68200
2021-12-11 17:54:46iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg408325

resolution: out of date
stage: patch review -> resolved
2018-08-17 20:35:40berker.peksagsetnosy: + berker.peksag
messages: + msg323667
2015-04-19 19:33:15christian.heimescreate