snmp_agent: fix c_avl_pick() segmentation fault.
authorKorynkevych, RomanX <romanx.korynkevych@intel.com>
Thu, 12 Jan 2017 11:24:27 +0000 (11:24 +0000)
committerKorynkevych, RomanX <romanx.korynkevych@intel.com>
Fri, 27 Jan 2017 14:15:43 +0000 (14:15 +0000)
Segmentation fault caused by c_avl_pick() occurs when NULL
iterator is passed.

Change-Id: I3dc960f80b556e18616717ca53fd992c8cf9d78b
Signed-off-by: Korynkevych, RomanX <romanx.korynkevych@intel.com>
src/daemon/utils_avltree.c
src/snmp_agent.c

index 92259ae..1cf3edf 100644 (file)
@@ -534,6 +534,8 @@ int c_avl_pick(c_avl_tree_t *t, void **key, void **value) {
   c_avl_node_t *n;
   c_avl_node_t *p;
 
+  assert(t != NULL);
+
   if ((key == NULL) || (value == NULL))
     return (-1);
   if (t->root == NULL)
index 74c2d0b..5f8ed29 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * collectd - src/snmp_agent.c
  *
- * Copyright(c) 2016 Intel Corporation. All rights reserved.
+ * Copyright(c) 2017 Intel Corporation. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  * this software and associated documentation files (the "Software"), to deal in
@@ -416,12 +416,14 @@ static void snmp_agent_free_table(table_definition_t **td) {
   c_avl_destroy((*td)->index_instance);
   (*td)->index_instance = NULL;
 
-  while (c_avl_pick((*td)->instance_index, &key, &value) == 0) {
-    sfree(key);
-    sfree(value);
+  if ((*td)->instance_index != NULL) {
+    while (c_avl_pick((*td)->instance_index, &key, &value) == 0) {
+      sfree(key);
+      sfree(value);
+    }
+    c_avl_destroy((*td)->instance_index);
+    (*td)->instance_index = NULL;
   }
-  c_avl_destroy((*td)->instance_index);
-  (*td)->instance_index = NULL;
 
   sfree((*td)->name);
   sfree(*td);