Skip to content

Commit 0efc024

Browse files
authored
Fix CID-1414686: PyInit_readline() handles errors (#4647)
Handle PyModule_AddIntConstant() and PyModule_AddStringConstant() failures. Add also constants before calling setup_readline(), since setup_readline() registers callbacks which uses a reference to the module, whereas the module is destroyed if adding constants fails. Fix Coverity warning: CID 1414686: Unchecked return value (CHECKED_RETURN) 2. check_return: Calling PyModule_AddStringConstant without checking return value (as is done elsewhere 45 out of 55 times).
1 parent 86afc1f commit 0efc024

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Modules/readline.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,13 +1352,27 @@ PyInit_readline(void)
13521352
if (m == NULL)
13531353
return NULL;
13541354

1355+
if (PyModule_AddIntConstant(m, "_READLINE_VERSION",
1356+
RL_READLINE_VERSION) < 0) {
1357+
goto error;
1358+
}
1359+
if (PyModule_AddIntConstant(m, "_READLINE_RUNTIME_VERSION",
1360+
rl_readline_version) < 0) {
1361+
goto error;
1362+
}
1363+
if (PyModule_AddStringConstant(m, "_READLINE_LIBRARY_VERSION",
1364+
rl_library_version) < 0)
1365+
{
1366+
goto error;
1367+
}
1368+
13551369
mod_state = (readlinestate *) PyModule_GetState(m);
13561370
PyOS_ReadlineFunctionPointer = call_readline;
13571371
setup_readline(mod_state);
13581372

1359-
PyModule_AddIntConstant(m, "_READLINE_VERSION", RL_READLINE_VERSION);
1360-
PyModule_AddIntConstant(m, "_READLINE_RUNTIME_VERSION", rl_readline_version);
1361-
PyModule_AddStringConstant(m, "_READLINE_LIBRARY_VERSION", rl_library_version);
1362-
13631373
return m;
1374+
1375+
error:
1376+
Py_DECREF(m);
1377+
return NULL;
13641378
}

0 commit comments

Comments
 (0)