[Freeswitch-svn] [commit] r8422 - freeswitch/trunk/src

Freeswitch SVN mikej at freeswitch.org
Thu May 15 17:08:42 EDT 2008


Author: mikej
Date: Thu May 15 17:08:42 2008
New Revision: 8422

Modified:
   freeswitch/trunk/src/switch_channel.c

Log:
handle buffer boundries a bit better, assert before deref. Found by Klockwork (www.klocwork.com)

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Thu May 15 17:08:42 2008
@@ -130,7 +130,7 @@
 	uint8_t x;
 	const char *str = "UNKNOWN";
 
-	for (x = 0; CAUSE_CHART[x].name; x++) {
+	for (x = 0; x < (sizeof(CAUSE_CHART) / sizeof(struct switch_cause_table)) ; x++) {
 		if (CAUSE_CHART[x].cause == cause) {
 			str = CAUSE_CHART[x].name;
 		}
@@ -147,7 +147,7 @@
 	if (*str > 47 && *str < 58) {
 		cause = atoi(str);
 	} else {
-		for (x = 0; CAUSE_CHART[x].name; x++) {
+		for (x = 0; x < (sizeof(CAUSE_CHART) / sizeof(struct switch_cause_table)) && CAUSE_CHART[x].name; x++) {
 			if (!strcasecmp(CAUSE_CHART[x].name, str)) {
 				cause = CAUSE_CHART[x].cause;
 			}
@@ -1272,10 +1272,9 @@
 	int index, i = channel->state_handler_index;
 	const switch_state_handler_table_t *new_handlers[SWITCH_MAX_STATE_HANDLERS] = { 0 };
 
+	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->flag_mutex);
-
-	switch_assert(channel != NULL);
 	channel->state_handler_index = 0;
 
 	if (state_handler) {



More information about the Freeswitch-svn mailing list