From 5b9630d76f7a899633037045e753ebf0542ebbef Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 3 Dec 2006 18:43:53 +0100 Subject: [PATCH] email plugin: Limit the `MaxConns' option by a hardcoded value. Because typos (and ``typos'', i. e. dumb users) happen, it's better to not allow INT_MAX connections. The problem is that on 32bit machines this would a) create 2147483648 threads b) allocate (at least) 512 GBytes of memory which would result in certain death of either the daemon or the system. This patch limits the number of connections (and thus threads and allocated memory) to 16384, which ought to be enough for most people. Those, who need more connections (and can accomplish this, even though there are quite narrow OS limits) will need to recompile themselves. --- src/email.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/email.c b/src/email.c index 6838eade..b7995973 100644 --- a/src/email.c +++ b/src/email.c @@ -73,6 +73,7 @@ #define SOCK_PATH "/tmp/.collectd-email" #define MAX_CONNS 5 +#define MAX_CONNS_LIMIT 16384 /* * Private data structures @@ -205,8 +206,17 @@ static int email_config (char *key, char *value) else if (0 == strcasecmp (key, "MaxConns")) { long int tmp = strtol (value, NULL, 0); - if (INT_MAX < tmp) { - max_conns = INT_MAX; + if (tmp < 1) { + fprintf (stderr, "email plugin: `MaxConns' was set to invalid " + "value %li, will use default %i.\n", + tmp, MAX_CONNS); + max_conns = MAX_CONNS; + } + else if (tmp > MAX_CONNS_LIMIT) { + fprintf (stderr, "email plugin: `MaxConns' was set to invalid " + "value %li, will use hardcoded limit %i.\n", + tmp, MAX_CONNS_LIMIT); + max_conns = MAX_CONNS_LIMIT; } else { max_conns = (int)tmp; -- 2.30.2