Merge branch 'collectd-5.4' into collectd-5.5
authorFlorian Forster <octo@collectd.org>
Sat, 5 Dec 2015 22:07:14 +0000 (23:07 +0100)
committerFlorian Forster <octo@collectd.org>
Sat, 5 Dec 2015 22:07:14 +0000 (23:07 +0100)
src/daemon/common.c
src/daemon/filter_chain.c
src/daemon/meta_data.c
src/iptables.c
src/libcollectdclient/network.c

index 53c1f08..fba51ef 100644 (file)
@@ -1170,6 +1170,9 @@ int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds)
        char *ptr;
        char *saveptr;
 
+       if ((buffer == NULL) || (vl == NULL) || (ds == NULL))
+               return EINVAL;
+
        i = -1;
        dummy = buffer;
        saveptr = NULL;
index 5042913..ecc7f16 100644 (file)
@@ -904,17 +904,17 @@ int fc_process_chain (const data_set_t *ds, value_list_t *vl, /* {{{ */
 {
   fc_rule_t *rule;
   fc_target_t *target;
-  int status;
+  int status = FC_TARGET_CONTINUE;
 
   if (chain == NULL)
     return (-1);
 
   DEBUG ("fc_process_chain (chain = %s);", chain->name);
 
-  status = FC_TARGET_CONTINUE;
   for (rule = chain->rules; rule != NULL; rule = rule->next)
   {
     fc_match_t *match;
+    status = FC_TARGET_CONTINUE;
 
     if (rule->name[0] != 0)
     {
@@ -976,8 +976,7 @@ int fc_process_chain (const data_set_t *ds, value_list_t *vl, /* {{{ */
       }
     }
 
-    if ((status == FC_TARGET_STOP)
-        || (status == FC_TARGET_RETURN))
+    if ((status == FC_TARGET_STOP) || (status == FC_TARGET_RETURN))
     {
       if (rule->name[0] != 0)
       {
@@ -988,20 +987,10 @@ int fc_process_chain (const data_set_t *ds, value_list_t *vl, /* {{{ */
       }
       break;
     }
-    else
-    {
-      status = FC_TARGET_CONTINUE;
-    }
   } /* for (rule) */
 
-  if (status == FC_TARGET_STOP)
-    return (FC_TARGET_STOP);
-  else if (status == FC_TARGET_RETURN)
-    return (FC_TARGET_CONTINUE);
-
-  /* for-loop has been aborted: A target returned `FC_TARGET_STOP' */
-  if (rule != NULL)
-    return (FC_TARGET_CONTINUE);
+  if ((status == FC_TARGET_STOP) || (status == FC_TARGET_RETURN))
+    return (status);
 
   DEBUG ("fc_process_chain (%s): Executing the default targets.",
       chain->name);
index 4e46ed5..e1d0ec5 100644 (file)
@@ -114,6 +114,8 @@ static meta_entry_t *md_entry_clone (const meta_entry_t *orig) /* {{{ */
     return (NULL);
 
   copy = md_entry_alloc (orig->key);
+  if (copy == NULL)
+    return (NULL);
   copy->type = orig->type;
   if (copy->type == MD_TYPE_STRING)
     copy->value.mv_string = strdup (orig->value.mv_string);
index 606b24d..590b693 100644 (file)
@@ -111,132 +111,127 @@ static int iptables_config (const char *key, const char *value)
                ip_version = IPV4;
        else if (strcasecmp (key, "Chain6") == 0)
                ip_version = IPV6;
+       else
+               return (1);
 
-       if (( ip_version == IPV4 ) || ( ip_version == IPV6 ))
-       {
-               ip_chain_t temp, *final, **list;
-               char *table;
-               int   table_len;
-               char *chain;
-               int   chain_len;
-
-               char *value_copy;
-               char *fields[4];
-               int   fields_num;
-               
-               memset (&temp, 0, sizeof (temp));
-
-               value_copy = strdup (value);
-               if (value_copy == NULL)
-               {
-                   char errbuf[1024];
-                   ERROR ("strdup failed: %s",
-                           sstrerror (errno, errbuf, sizeof (errbuf)));
-                   return (1);
-               }
+       ip_chain_t temp, *final, **list;
+       char *table;
+       int   table_len;
+       char *chain;
+       int   chain_len;
 
-               /*
-                *  Time to fill the temp element
-                *  Examine value string, it should look like:
-                *  Chain[6] <table> <chain> [<comment|num> [name]]
-                        */
+       char *value_copy;
+       char *fields[4];
+       int   fields_num;
 
-               /* set IPv4 or IPv6 */
-                temp.ip_version = ip_version;
+       memset (&temp, 0, sizeof (temp));
 
-               /* Chain <table> <chain> [<comment|num> [name]] */
-               fields_num = strsplit (value_copy, fields, 4);
-               if (fields_num < 2)
-               {
-                   free (value_copy);
-                   return (1);
-               }
+       value_copy = strdup (value);
+       if (value_copy == NULL)
+       {
+           char errbuf[1024];
+           ERROR ("strdup failed: %s",
+                   sstrerror (errno, errbuf, sizeof (errbuf)));
+           return (1);
+       }
 
-               table = fields[0];
-               chain = fields[1];
+       /*
+        *  Time to fill the temp element
+        *  Examine value string, it should look like:
+        *  Chain[6] <table> <chain> [<comment|num> [name]]
+        */
 
-               table_len = strlen (table) + 1;
-               if ((unsigned int)table_len > sizeof(temp.table))
-               {
-                       ERROR ("Table `%s' too long.", table);
-                       free (value_copy);
-                       return (1);
-               }
-               sstrncpy (temp.table, table, table_len);
+       /* set IPv4 or IPv6 */
+       temp.ip_version = ip_version;
 
-               chain_len = strlen (chain) + 1;
-               if ((unsigned int)chain_len > sizeof(temp.chain))
-               {
-                       ERROR ("Chain `%s' too long.", chain);
-                       free (value_copy);
-                       return (1);
-               }
-               sstrncpy (temp.chain, chain, chain_len);
+       /* Chain <table> <chain> [<comment|num> [name]] */
+       fields_num = strsplit (value_copy, fields, 4);
+       if (fields_num < 2)
+       {
+           free (value_copy);
+           return (1);
+       }
 
-               if (fields_num >= 3)
-               {
-                   char *comment = fields[2];
-                   int   rule = atoi (comment);
-
-                   if (rule)
-                   {
-                       temp.rule.num = rule;
-                       temp.rule_type = RTYPE_NUM;
-                   }
-                   else
-                   {
-                       temp.rule.comment = strdup (comment);
-                       if (temp.rule.comment == NULL)
-                       {
-                           free (value_copy);
-                           return (1);
-                       }
-                       temp.rule_type = RTYPE_COMMENT;
-                   }
-               }
-               else
-               {
-                   temp.rule_type = RTYPE_COMMENT_ALL;
-               }
+       table = fields[0];
+       chain = fields[1];
 
-               if (fields_num >= 4)
-                   sstrncpy (temp.name, fields[3], sizeof (temp.name));
+       table_len = strlen (table) + 1;
+       if ((unsigned int)table_len > sizeof(temp.table))
+       {
+               ERROR ("Table `%s' too long.", table);
+               free (value_copy);
+               return (1);
+       }
+       sstrncpy (temp.table, table, table_len);
 
+       chain_len = strlen (chain) + 1;
+       if ((unsigned int)chain_len > sizeof(temp.chain))
+       {
+               ERROR ("Chain `%s' too long.", chain);
                free (value_copy);
-               value_copy = NULL;
-               table = NULL;
-               chain = NULL;
+               return (1);
+       }
+       sstrncpy (temp.chain, chain, chain_len);
 
-               list = (ip_chain_t **) realloc (chain_list, (chain_num + 1) * sizeof (ip_chain_t *));
-               if (list == NULL)
+       if (fields_num >= 3)
+       {
+           char *comment = fields[2];
+           int   rule = atoi (comment);
+
+           if (rule)
+           {
+               temp.rule.num = rule;
+               temp.rule_type = RTYPE_NUM;
+           }
+           else
+           {
+               temp.rule.comment = strdup (comment);
+               if (temp.rule.comment == NULL)
                {
-                   char errbuf[1024];
-                   ERROR ("realloc failed: %s",
-                           sstrerror (errno, errbuf, sizeof (errbuf)));
-                   sfree (temp.rule.comment);
+                   free (value_copy);
                    return (1);
                }
+               temp.rule_type = RTYPE_COMMENT;
+           }
+       }
+       else
+       {
+           temp.rule_type = RTYPE_COMMENT_ALL;
+       }
 
-               chain_list = list;
-               final = (ip_chain_t *) malloc( sizeof(temp) );
-               if (final == NULL) 
-               {
-                   char errbuf[1024];
-                   ERROR ("malloc failed: %s",
-                           sstrerror (errno, errbuf, sizeof (errbuf)));
-                   sfree (temp.rule.comment);
-                   return (1);
-               }
-               memcpy (final, &temp, sizeof (temp));
-               chain_list[chain_num] = final;
-               chain_num++;
+       if (fields_num >= 4)
+           sstrncpy (temp.name, fields[3], sizeof (temp.name));
 
-               DEBUG ("Chain #%i: table = %s; chain = %s;", chain_num, final->table, final->chain);
+       free (value_copy);
+       value_copy = NULL;
+       table = NULL;
+       chain = NULL;
+
+       list = (ip_chain_t **) realloc (chain_list, (chain_num + 1) * sizeof (ip_chain_t *));
+       if (list == NULL)
+       {
+           char errbuf[1024];
+           ERROR ("realloc failed: %s",
+                   sstrerror (errno, errbuf, sizeof (errbuf)));
+           sfree (temp.rule.comment);
+           return (1);
        }
-       else 
+
+       chain_list = list;
+       final = (ip_chain_t *) malloc( sizeof(temp) );
+       if (final == NULL)
        {
-               return (-1);
+           char errbuf[1024];
+           ERROR ("malloc failed: %s",
+                   sstrerror (errno, errbuf, sizeof (errbuf)));
+           sfree (temp.rule.comment);
+           return (1);
        }
+       memcpy (final, &temp, sizeof (temp));
+       chain_list[chain_num] = final;
+       chain_num++;
+
+       DEBUG ("Chain #%i: table = %s; chain = %s;", chain_num, final->table, final->chain);
 
        return (0);
 } /* int iptables_config */
index c390a1c..a3b8fdf 100644 (file)
@@ -154,7 +154,6 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */
 
     if (ai_ptr->ai_family == AF_INET)
     {
-
       struct sockaddr_in *addr = (struct sockaddr_in *) ai_ptr->ai_addr;
       int optname;
 
@@ -163,9 +162,8 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */
       else
         optname = IP_TTL;
 
-      setsockopt (srv->fd, IPPROTO_IP, optname,
-          &srv->ttl,
-          sizeof (srv->ttl));
+      status = setsockopt (srv->fd, IPPROTO_IP, optname,
+          &srv->ttl, sizeof (srv->ttl));
     }
     else if (ai_ptr->ai_family == AF_INET6)
     {
@@ -178,9 +176,15 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */
       else
         optname = IPV6_UNICAST_HOPS;
 
-      setsockopt (srv->fd, IPPROTO_IPV6, optname,
-          &srv->ttl,
-          sizeof (srv->ttl));
+      status = setsockopt (srv->fd, IPPROTO_IPV6, optname,
+          &srv->ttl, sizeof (srv->ttl));
+    }
+    if (status != 0)
+    {
+      /* setsockopt failed. */
+      close (srv->fd);
+      srv->fd = -1;
+      continue;
     }
 
     srv->sa = malloc (ai_ptr->ai_addrlen);