From 5feb9367551431c88165f9502d116ca98f6ca041 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Fri, 13 Feb 2015 08:37:24 +0100 Subject: [PATCH] add some checks for PyList_New() which were missing --- psutil/_psutil_bsd.c | 7 ++++--- psutil/_psutil_posix.c | 3 ++- psutil/_psutil_windows.c | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index 615c04bae..f15e61ebf 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -1506,9 +1506,9 @@ psutil_net_io_counters(PyObject *self, PyObject *args) size_t len; PyObject *py_retdict = PyDict_New(); PyObject *py_ifc_info = NULL; + if (py_retdict == NULL) return NULL; - mib[0] = CTL_NET; // networking subsystem mib[1] = PF_ROUTE; // type of information mib[2] = 0; // protocol (IPPROTO_xxx) @@ -1597,9 +1597,9 @@ psutil_disk_io_counters(PyObject *self, PyObject *args) PyObject *py_retdict = PyDict_New(); PyObject *py_disk_info = NULL; + if (py_retdict == NULL) return NULL; - if (devstat_checkversion(NULL) < 0) { PyErr_Format(PyExc_RuntimeError, "devstat_checkversion() failed"); goto error; @@ -2038,9 +2038,10 @@ psutil_net_connections(PyObject* self, PyObject* args) { PyObject *py_retlist = PyList_New(0); + if (py_retlist == NULL) + return NULL; if (psutil_populate_xfiles() != 1) goto error; - if (psutil_gather_inet(IPPROTO_TCP, py_retlist) == 0) goto error; if (psutil_gather_inet(IPPROTO_UDP, py_retlist) == 0) diff --git a/psutil/_psutil_posix.c b/psutil/_psutil_posix.c index 8556a6bc5..f0bcffc44 100644 --- a/psutil/_psutil_posix.c +++ b/psutil/_psutil_posix.c @@ -166,7 +166,8 @@ psutil_net_if_addrs(PyObject* self, PyObject* args) PyObject *py_netmask = NULL; PyObject *py_broadcast = NULL; - + if (py_retlist == NULL) + return NULL if (getifaddrs(&ifaddr) == -1) { PyErr_SetFromErrno(PyExc_OSError); goto error; diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 0ee9d9a3c..d70a768b1 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -3021,6 +3021,8 @@ psutil_net_if_addrs(PyObject *self, PyObject *args) PyObject *py_address = NULL; PyObject *py_mac_address = NULL; + if (py_retlist == NULL) + return NULL; // allocate a 15 KB buffer to start with outBufLen = 15000;