Skip to content

Commit e677617

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Add NULL checks for atexit import during CinderX module init
Summary: PyImport_ImportModule("atexit") and the subsequent PyObject_GetAttrString were used without NULL checks. If either failed, the next call would receive a nullptr argument, causing undefined behavior. Add early-return error checks consistent with the existing pattern used for other imports in the same function. Reviewed By: yoney Differential Revision: D94680101 fbshipit-source-id: a9f0444f0bd06286b68b74d25f1037861d8d7e15
1 parent eb31409 commit e677617

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

cinderx/_cinderx-lib.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,13 @@ int _cinderx_exec_impl(PyObject* m) {
14251425
// happens so we can clear out strict modules first, so we register
14261426
// directly with the atexit library.
14271427
auto atexit = Ref<>::steal(PyImport_ImportModule("atexit"));
1428+
if (atexit == nullptr) {
1429+
return -1;
1430+
}
14281431
auto register_func = Ref<>::steal(PyObject_GetAttrString(atexit, "register"));
1432+
if (register_func == nullptr) {
1433+
return -1;
1434+
}
14291435
auto clear_strict_modules_func =
14301436
Ref<>::steal(PyObject_GetAttrString(m, "_clear_strict_modules"));
14311437
if (clear_strict_modules_func == nullptr) {

0 commit comments

Comments
 (0)