From 5ff8716e8e1902734c787533dbdb0f5276fb2d40 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 5 Jan 2010 16:30:58 +0000 Subject: [PATCH] added more proper checks and fixes to last commit git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@945 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 10 ++---- libs/freetdm/src/zap_io.c | 33 ++++++++++++------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 3dfe91006c..94dbcb58aa 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -401,7 +401,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) *zchan = NULL; } zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n"); - zap_log(ZAP_LOG_CRIT, "DYDBG s%dc%d: Csid:%d Timed out waiting for boost channel request response, current status: BST_WAITING\n", (*zchan)->physical_span_id, (*zchan)->physical_chan_id, r); + zap_log(ZAP_LOG_CRIT, "s%dc%d: Csid:%d Timed out waiting for boost channel request response, current status: BST_WAITING\n", (*zchan)->physical_span_id, (*zchan)->physical_chan_id, r); goto done; } } @@ -683,7 +683,7 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco event->release_cause = 17; } - zap_log(ZAP_LOG_CRIT, "DYDBG setting event->call_setup_id:%d to BST_FAIL\n", event->call_setup_id); + zap_log(ZAP_LOG_DEBUG, "setting event->call_setup_id:%d to BST_FAIL\n", event->call_setup_id); OUTBOUND_REQUESTS[event->call_setup_id].event = *event; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; if (!sangoma_boost_data->sigmod) { @@ -1565,7 +1565,6 @@ end: */ static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) { - int i; g_boost_modules_hash = create_hashtable(10, zap_hash_hashfromstring, zap_hash_equalkeys); if (!g_boost_modules_hash) { return ZAP_FAIL; @@ -1573,10 +1572,7 @@ static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) zap_mutex_create(&request_mutex); zap_mutex_create(&signal_mutex); zap_mutex_create(&g_boost_modules_mutex); - - for(i=0;i< MAX_TRUNK_GROUPS;i++) { - g_trunkgroups[i]=NULL; - } + memset(&g_trunkgroups[0], 0, sizeof(g_trunkgroups)); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 124e371be3..e95550471c 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2552,6 +2552,7 @@ static zap_status_t load_config(void) char group_name[80] = "default"; zap_io_interface_t *zio = NULL; zap_analog_start_type_t tmp; + zap_size_t len = 0; if (!zap_config_open_file(&cfg, cfg_name)) { return ZAP_FAIL; @@ -2707,8 +2708,13 @@ static zap_status_t load_config(void) span->dtmf_hangup = zap_strdup(val); span->dtmf_hangup_len = strlen(val); } else if (!strcasecmp(var, "group")) { - memset(group_name, 0, sizeof(group_name)); - memcpy(group_name, val, sizeof(group_name)); + len = strlen(val); + if (len >= sizeof(group_name)) { + len = sizeof(group_name) - 1; + zap_log(ZAP_LOG_WARNING, "Truncating group name %s to %zd length\n", val, len); + } + zap_copy_string(group_name, val, len); + group_name[len] = '\0'; } else { zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var); } @@ -2728,7 +2734,8 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) zap_config_t cfg; char *var, *val; char filename[256] = ""; - assert(zio != NULL); + + zap_assert_return(zio != NULL, ZAP_FAIL, "zio argument is null\n"); snprintf(filename, sizeof(filename), "%s.conf", zio->name); @@ -3071,7 +3078,7 @@ OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* sp p = strchr(val, ':'); mydata = zap_strdup(++p); - assert(mydata != NULL); + zap_assert_return(mydata != NULL, ZAP_FAIL, "zap_strdup failed when adding channels\n"); items = zap_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0]))); @@ -3080,14 +3087,13 @@ OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* sp int chan_no; chan_no = atoi (item_list[i]); - assert(chan_no > 0); + zap_assert(chan_no > 0, "Channel number is not bigger than zero, expect a nasty failure!\n"); if (zap_channel_add_to_group(name, span->channels[chan_no]) != ZAP_SUCCESS) { zap_log(ZAP_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_no, name); } } else { int chan_no_start, chan_no_end; - if (sscanf(item_list[i], "%d-%d", &chan_no_start, &chan_no_end) == 2) { while (chan_no_start <= chan_no_end) { if (zap_channel_add_to_group(name, span->channels[chan_no_start++])) { @@ -3097,6 +3103,7 @@ OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* sp } } } + zap_safe_free(mydata); return ZAP_SUCCESS; } @@ -3131,7 +3138,7 @@ OZ_DECLARE(zap_status_t) zap_group_find(uint32_t id, zap_group_t **group) OZ_DECLARE(zap_status_t) zap_group_find_by_name(const char *name, zap_group_t **group) { zap_status_t status = ZAP_FAIL; - + *group = NULL; zap_mutex_lock(globals.group_mutex); if (!zap_strlen_zero(name)) { if ((*group = hashtable_search(globals.group_hash, (void *) name))) { @@ -3167,17 +3174,21 @@ OZ_DECLARE(zap_status_t) zap_group_create(zap_group_t **group, const char *name) zap_mutex_lock(globals.mutex); if (globals.group_index < ZAP_MAX_GROUPS_INTERFACE) { - new_group = zap_malloc(sizeof(*new_group)); - assert(new_group); - memset(new_group, 0, sizeof(*new_group)); + new_group = zap_calloc(1, sizeof(*new_group)); + + zap_assert(new_group != NULL, "Failed to create new zap group, expect a crash\n"); + status = zap_mutex_create(&new_group->mutex); - assert(status == ZAP_SUCCESS); + + zap_assert(status == ZAP_SUCCESS, "Failed to create group mutex, expect a crash\n"); new_group->group_id = ++globals.group_index; new_group->name = zap_strdup(name); zap_group_add(new_group); *group = new_group; status = ZAP_SUCCESS; + } else { + zap_log(ZAP_LOG_CRIT, "Group %s was not added, we exceeded the max number of groups\n", name); } zap_mutex_unlock(globals.mutex); return status;