diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-11-30 17:21:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-30 17:21:07 +0100 |
commit | 0efc0249ca1fd0675098957407fbba2c0f6949ce (patch) | |
tree | 8b7ed7b31def95c1bba20de71daefe66aeab2941 /Modules/readline.c | |
parent | 86afc1f2a7fb3afe00779c6426bc141bc795d9a3 (diff) | |
download | cpython-git-0efc0249ca1fd0675098957407fbba2c0f6949ce.tar.gz |
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).
Diffstat (limited to 'Modules/readline.c')
-rw-r--r-- | Modules/readline.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Modules/readline.c b/Modules/readline.c index d0e3b913e5..811fca8cd9 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -1352,13 +1352,27 @@ PyInit_readline(void) if (m == NULL) return NULL; + if (PyModule_AddIntConstant(m, "_READLINE_VERSION", + RL_READLINE_VERSION) < 0) { + goto error; + } + if (PyModule_AddIntConstant(m, "_READLINE_RUNTIME_VERSION", + rl_readline_version) < 0) { + goto error; + } + if (PyModule_AddStringConstant(m, "_READLINE_LIBRARY_VERSION", + rl_library_version) < 0) + { + goto error; + } + mod_state = (readlinestate *) PyModule_GetState(m); PyOS_ReadlineFunctionPointer = call_readline; setup_readline(mod_state); - PyModule_AddIntConstant(m, "_READLINE_VERSION", RL_READLINE_VERSION); - PyModule_AddIntConstant(m, "_READLINE_RUNTIME_VERSION", rl_readline_version); - PyModule_AddStringConstant(m, "_READLINE_LIBRARY_VERSION", rl_library_version); - return m; + +error: + Py_DECREF(m); + return NULL; } |