summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2021-01-07 12:05:57 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2021-01-07 12:05:57 +0100
commit5bf1f8ef336045da222255062dc344e7aa456eb9 (patch)
tree156145688aed3f45b723cc83156ce5a4499b166b
parent0476278bc4d3c8aebfd5df1181620c5a88c71c50 (diff)
downloadpsutil-5bf1f8ef336045da222255062dc344e7aa456eb9.tar.gz
set a limit for malloc() size
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
-rw-r--r--psutil/_psutil_osx.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c
index ee40bc9c..121b4f56 100644
--- a/psutil/_psutil_osx.c
+++ b/psutil/_psutil_osx.c
@@ -115,6 +115,7 @@ static struct proc_fdinfo*
psutil_proc_list_fds(pid_t pid, int *num_fds) {
int ret;
int fds_size = 0;
+ int max_size = 24 * 1024 * 1024; // 24M
struct proc_fdinfo *fds_pointer = NULL;
errno = 0;
@@ -128,6 +129,11 @@ psutil_proc_list_fds(pid_t pid, int *num_fds) {
if (ret > fds_size) {
while (ret > fds_size) {
fds_size += PROC_PIDLISTFD_SIZE * 32;
+ if (fds_size > max_size) {
+ PyErr_Format(PyExc_RuntimeError,
+ "malloc() exceeded 24M limit");
+ goto error;
+ }
}
psutil_debug("list_fds: allocate buf size %i", fds_size);