From 9e30a0c8227538cc11a3f83f021fb944c1279c2c Mon Sep 17 00:00:00 2001 From: "Korynkevych, RomanX" Date: Thu, 12 Jan 2017 11:24:27 +0000 Subject: [PATCH] snmp_agent: fix c_avl_pick() segmentation fault. Segmentation fault caused by c_avl_pick() occurs when NULL iterator is passed. Change-Id: I3dc960f80b556e18616717ca53fd992c8cf9d78b Signed-off-by: Korynkevych, RomanX --- src/daemon/utils_avltree.c | 2 ++ src/snmp_agent.c | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/daemon/utils_avltree.c b/src/daemon/utils_avltree.c index 92259ae1..1cf3edfc 100644 --- a/src/daemon/utils_avltree.c +++ b/src/daemon/utils_avltree.c @@ -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) diff --git a/src/snmp_agent.c b/src/snmp_agent.c index 74c2d0b0..5f8ed290 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -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); -- 2.30.2