From: Jia Zhouyang Date: Mon, 9 Mar 2020 02:21:29 +0000 (-0400) Subject: Add error handling for PyType_Ready X-Git-Tag: collectd-5.12.0~52^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f2e5192f64d11d9eb7413005c5f93980871095f;p=thirdparty%2Fcollectd.git Add error handling for PyType_Ready The API PyType_Ready may fail, when it happens, the program may crash. --- diff --git a/src/python.c b/src/python.c index a248fdad5..01314213b 100644 --- a/src/python.c +++ b/src/python.c @@ -1261,16 +1261,34 @@ static int cpy_init_python(void) { Py_Initialize(); python_sigint_handler = PyOS_setsig(SIGINT, cur_sig); - PyType_Ready(&ConfigType); - PyType_Ready(&PluginDataType); + if (PyType_Ready(&ConfigType) < 0) { + cpy_log_exception("python initialization: ConfigType"); + return 1; + } + if (PyType_Ready(&PluginDataType) < 0) { + cpy_log_exception("python initialization: PluginDataType"); + return 1; + } ValuesType.tp_base = &PluginDataType; - PyType_Ready(&ValuesType); + if (PyType_Ready(&ValuesType) < 0) { + cpy_log_exception("python initialization: ValuesType"); + return 1; + } NotificationType.tp_base = &PluginDataType; - PyType_Ready(&NotificationType); + if (PyType_Ready(&NotificationType) < 0) { + cpy_log_exception("python initialization: NotificationType"); + return 1; + } SignedType.tp_base = &PyLong_Type; - PyType_Ready(&SignedType); + if (PyType_Ready(&SignedType) < 0) { + cpy_log_exception("python initialization: SignedType"); + return 1; + } UnsignedType.tp_base = &PyLong_Type; - PyType_Ready(&UnsignedType); + if (PyType_Ready(&UnsignedType) < 0) { + cpy_log_exception("python initialization: UnsignedType"); + return 1; + } errordict = PyDict_New(); PyDict_SetItemString( errordict, "__doc__",