Skip to content

Commit 4e928d6

Browse files
author
David Sommerseth
committed
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>
1 parent aa2c20e commit 4e928d6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

python-ethtool/etherinfo_obj.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,42 @@ PyObject * _ethtool_etherinfo_get_ipv6_addresses(etherinfo_py *self, PyObject *n
222222
get_etherinfo(self->data->ethinfo, self->data->nlc, NLQRY_ADDR);
223223
ipv6 = self->data->ethinfo->ipv6_addresses;
224224
ret = PyTuple_New(1);
225+
if( !ret ) {
226+
PyErr_SetString(PyExc_MemoryError,
227+
"[INTERNAL] Failed to allocate tuple list for "
228+
"IPv6 address objects");
229+
return NULL;
230+
}
225231
while( ipv6 ) {
226232
PyObject *ipv6_pyobj = NULL, *ipv6_pydata = NULL, *args = NULL;
227233
struct ipv6address *next = ipv6->next;
228234

229235
ipv6->next = NULL;
230236
ipv6_pydata = PyCObject_FromVoidPtr(ipv6, NULL);
237+
if( !ipv6_pydata ) {
238+
PyErr_SetString(PyExc_MemoryError,
239+
"[INTERNAL] Failed to create python object "
240+
"containing IPv6 address");
241+
return NULL;
242+
}
231243
args = PyTuple_New(1);
244+
if( !args ) {
245+
PyErr_SetString(PyExc_MemoryError,
246+
"[INTERNAL] Failed to allocate argument list "
247+
"a new IPv6 address object");
248+
return NULL;
249+
}
232250
PyTuple_SetItem(args, 0, ipv6_pydata);
233251
ipv6_pyobj = PyObject_CallObject((PyObject *)&ethtool_etherinfoIPv6Type, args);
234252
if( ipv6_pyobj ) {
235253
PyTuple_SetItem(ret, i++, ipv6_pyobj);
236254
_PyTuple_Resize(&ret, i+1);
237255
Py_INCREF(ipv6_pyobj);
256+
} else {
257+
PyErr_SetString(PyExc_RuntimeError,
258+
"[INTERNAL] Failed to initialise the new "
259+
"IPv6 address object");
260+
return NULL;
238261
}
239262
ipv6 = next;
240263
}

0 commit comments

Comments
 (0)