[monitoring-plugins] avoid a segfault, if ulimit is set to unlimited

Sven Nierlein git at monitoring-plugins.org
Fri Nov 28 15:30:08 CET 2014


    Module: monitoring-plugins
    Branch: pr-1183-enhanced
    Commit: 6bb5e1db525f44a7ab40e9391244dbe65daa08cc
    Author: nafets <fis.stefan at gmail.com>
 Committer: Sven Nierlein <sven at nierlein.de>
      Date: Wed Nov 19 22:34:23 2014 +0100
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=6bb5e1d

avoid a segfault, if ulimit is set to unlimited

---

 lib/utils_cmd.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c
index 9e214bd..e41a982 100644
--- a/lib/utils_cmd.c
+++ b/lib/utils_cmd.c
@@ -116,6 +116,14 @@ cmd_init (void)
 	}
 #endif
 
+	/* if maxfd is unnaturally high, we force it to a lower value
+	 * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause
+	 * a segfault when following calloc is called ...  ) */
+
+	if ( maxfd > 2048 ) {
+		maxfd = 2048;
+	}
+
 	if (!_cmd_pids)
 		_cmd_pids = calloc (maxfd, sizeof (pid_t));
 }



More information about the Commits mailing list