Code

email plugin: Limit the `MaxConns' option by a hardcoded value.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 3 Dec 2006 17:43:53 +0000 (18:43 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 3 Dec 2006 17:43:53 +0000 (18:43 +0100)
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

index 6838eade148ca29c343e0cf0b71c97e5b5b238a5..b7995973dae20556392908d52298bafd79c70d88 100644 (file)
@@ -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;