From 4e928d62a8e3c1dfefe6a55b81c0f0b4510b14eb Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 25 Feb 2011 12:03:54 +0100 Subject: Improved error situations in case of NULL returns _ethtool_etherinfo_get_ipv6_addresses() didn't check too well several Python calls if it would return NULL. Reported-by: Dave Malcolm Signed-off-by: David Sommerseth --- python-ethtool/etherinfo_obj.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/python-ethtool/etherinfo_obj.c b/python-ethtool/etherinfo_obj.c index 04eb634..aefb940 100644 --- a/python-ethtool/etherinfo_obj.c +++ b/python-ethtool/etherinfo_obj.c @@ -222,19 +222,42 @@ PyObject * _ethtool_etherinfo_get_ipv6_addresses(etherinfo_py *self, PyObject *n get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_ADDR); ipv6 = self->data->ethinfo->ipv6_addresses; ret = PyTuple_New(1); + if( !ret ) { + PyErr_SetString(PyExc_MemoryError, + "[INTERNAL] Failed to allocate tuple list for " + "IPv6 address objects"); + return NULL; + } while( ipv6 ) { PyObject *ipv6_pyobj = NULL, *ipv6_pydata = NULL, *args = NULL; struct ipv6address *next = ipv6->next; ipv6->next = NULL; ipv6_pydata = PyCObject_FromVoidPtr(ipv6, NULL); + if( !ipv6_pydata ) { + PyErr_SetString(PyExc_MemoryError, + "[INTERNAL] Failed to create python object " + "containing IPv6 address"); + return NULL; + } args = PyTuple_New(1); + if( !args ) { + PyErr_SetString(PyExc_MemoryError, + "[INTERNAL] Failed to allocate argument list " + "a new IPv6 address object"); + return NULL; + } PyTuple_SetItem(args, 0, ipv6_pydata); ipv6_pyobj = PyObject_CallObject((PyObject *)ðtool_etherinfoIPv6Type, args); if( ipv6_pyobj ) { PyTuple_SetItem(ret, i++, ipv6_pyobj); _PyTuple_Resize(&ret, i+1); Py_INCREF(ipv6_pyobj); + } else { + PyErr_SetString(PyExc_RuntimeError, + "[INTERNAL] Failed to initialise the new " + "IPv6 address object"); + return NULL; } ipv6 = next; } -- cgit