diff options
author | David Sommerseth <davids@redhat.com> | 2011-02-25 12:03:54 +0100 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2011-02-25 12:10:22 +0100 |
commit | 4e928d62a8e3c1dfefe6a55b81c0f0b4510b14eb (patch) | |
tree | cad5e751f6674b0a861a207af7b90217017eb062 /python-ethtool | |
parent | aa2c20e697af1907b92129410aa10952a3ffdd68 (diff) | |
download | python-ethtool-4e928d62a8e3c1dfefe6a55b81c0f0b4510b14eb.tar.gz python-ethtool-4e928d62a8e3c1dfefe6a55b81c0f0b4510b14eb.tar.xz python-ethtool-4e928d62a8e3c1dfefe6a55b81c0f0b4510b14eb.zip |
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 <dmalcolm@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'python-ethtool')
-rw-r--r-- | python-ethtool/etherinfo_obj.c | 23 |
1 files changed, 23 insertions, 0 deletions
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; } |