diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c index 99069f56a..0717f1950 100644 --- a/psutil/_psutil_sunos.c +++ b/psutil/_psutil_sunos.c @@ -1173,7 +1173,7 @@ psutil_net_connections(PyObject *self, PyObject *args) { mibhdr.len = 0; #endif memcpy(buf, &tor, sizeof tor); - memcpy(buf + sizeof tor, &mibhdr, sizeof mibhdr); + memcpy(buf + tor.OPT_offset, &mibhdr, sizeof mibhdr); ctlbuf.buf = buf; ctlbuf.len = tor.OPT_offset + tor.OPT_length; @@ -1213,6 +1213,9 @@ psutil_net_connections(PyObject *self, PyObject *args) { goto error; } + memset(&mibhdr, 0x0, sizeof(mibhdr)); + memcpy(&mibhdr, buf + toa.OPT_offset, toa.OPT_length); + databuf.maxlen = mibhdr.len; databuf.len = 0; databuf.buf = (char *)malloc((int)mibhdr.len);