diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2022-09-19 14:59:58 -0700 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2022-09-19 14:59:58 -0700 |
commit | f4784d0789cbb911836f5cfcfa0e8a513af6b381 (patch) | |
tree | e9e86a5cd865105fd890a01b138fbfd177546e4d | |
parent | b88f4d839dc4d665526e91b098d018a3d796a0ac (diff) | |
download | psutil-f4784d0789cbb911836f5cfcfa0e8a513af6b381.tar.gz |
fix #2116, macOS, net_connections() crashing
It turns out that proc_pidinfo() crashes for PID 0
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
-rw-r--r-- | HISTORY.rst | 1 | ||||
-rw-r--r-- | psutil/_psutil_osx.c | 8 |
2 files changed, 9 insertions, 0 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index 00bd5043..e088de08 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,7 @@ XXXX-XX-XX **Bug fixes** +- 2116_, [macOS]: `psutil.net_connections`_ fails with RuntimeError. - 2135_, [macOS]: `Process.environ()`_ may contain garbage data. Fix out-of-bounds read around ``sysctl_procargs``. (patch by Bernhard Urban-Forster) - 2138_, [Linux], **[critical]**: can't compile psutil on Android due to diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index 2470c3eb..cd375bab 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -955,6 +955,10 @@ psutil_proc_open_files(PyObject *self, PyObject *args) { if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid)) goto error; + // see: https://github.com/giampaolo/psutil/issues/2116 + if (pid == 0) + return py_retlist; + fds_pointer = psutil_proc_list_fds(pid, &num_fds); if (fds_pointer == NULL) goto error; @@ -1047,6 +1051,10 @@ psutil_proc_connections(PyObject *self, PyObject *args) { goto error; } + // see: https://github.com/giampaolo/psutil/issues/2116 + if (pid == 0) + return py_retlist; + if (!PySequence_Check(py_af_filter) || !PySequence_Check(py_type_filter)) { PyErr_SetString(PyExc_TypeError, "arg 2 or 3 is not a sequence"); goto error; |