[svn-commits] jpeeler: branch 1.4 r271552 - /branches/1.4/pbx/pbx_ael.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jun 21 15:37:54 CDT 2010


Author: jpeeler
Date: Mon Jun 21 15:37:47 2010
New Revision: 271552

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=271552
Log:
Do not use sizeof to calculate size of a heap allocated character array.

Change left out from 271399.

(closes issue #16053)
Reported by: diLLec

Modified:
    branches/1.4/pbx/pbx_ael.c

Modified: branches/1.4/pbx/pbx_ael.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/pbx/pbx_ael.c?view=diff&rev=271552&r1=271551&r2=271552
==============================================================================
--- branches/1.4/pbx/pbx_ael.c (original)
+++ branches/1.4/pbx/pbx_ael.c Mon Jun 21 15:37:47 2010
@@ -58,6 +58,8 @@
 #define DEBUG_TOKENS (1 << 1)
 #define DEBUG_MACROS (1 << 2)
 #define DEBUG_CONTEXTS (1 << 3)
+
+#define BUF_SIZE 2000
 
 static char *config = "extensions.ael";
 static char *registrar = "pbx_ael";
@@ -3210,13 +3212,13 @@
 	struct ael_priority *loop_continue_save;
 	struct ael_extension *switch_case,*switch_null;
 
-	if (!(buf1 = malloc(2000))) {
+	if (!(buf1 = malloc(BUF_SIZE))) {
 		return -1;
 	}
-	if (!(buf2 = malloc(2000))) {
+	if (!(buf2 = malloc(BUF_SIZE))) {
 		return -1;
 	}
-	if (!(new_label = malloc(2000))) {
+	if (!(new_label = malloc(BUF_SIZE))) {
 		return -1;
 	}
 	
@@ -3265,7 +3267,7 @@
 		case PV_VARDEC:
 			pr = new_prio();
 			pr->type = AEL_APPCALL;
-			snprintf(buf1,sizeof(buf1),"%s=$[%s]", p->u1.str, p->u2.val);
+			snprintf(buf1, BUF_SIZE, "%s=$[%s]", p->u1.str, p->u2.val);
 			pr->app = strdup("Set");
 			remove_spaces_before_equals(buf1);
 			pr->appargs = strdup(buf1);
@@ -3286,16 +3288,16 @@
 				if (!mother_exten)
 					pr->appargs = strdup(p->u1.list->u1.str);
 				else {  /* for the case of simple within-extension gotos in case/pattern/default statement blocks: */ 
-					snprintf(buf1,sizeof(buf1),"%s|%s", mother_exten->name, p->u1.list->u1.str);
+					snprintf(buf1, BUF_SIZE, "%s|%s", mother_exten->name, p->u1.list->u1.str);
 					pr->appargs = strdup(buf1);
 				}
 				
 			} else if (p->u1.list->next && !p->u1.list->next->next) /* two */ {
-				snprintf(buf1,sizeof(buf1),"%s|%s", p->u1.list->u1.str, p->u1.list->next->u1.str);
+				snprintf(buf1, BUF_SIZE, "%s|%s", p->u1.list->u1.str, p->u1.list->next->u1.str);
 				pr->app = strdup("Goto");
 				pr->appargs = strdup(buf1);
 			} else if (p->u1.list->next && p->u1.list->next->next) {
-				snprintf(buf1,sizeof(buf1),"%s|%s|%s", p->u1.list->u1.str, 
+				snprintf(buf1, BUF_SIZE, "%s|%s|%s", p->u1.list->u1.str, 
 						p->u1.list->next->u1.str,
 						p->u1.list->next->next->u1.str);
 				pr->app = strdup("Goto");
@@ -3317,7 +3319,7 @@
 			control_statement_count++;
 			loop_break_save = exten->loop_break; /* save them, then restore before leaving */
 			loop_continue_save = exten->loop_continue;
-			snprintf(new_label,sizeof(new_label),"for-%s-%d", label, control_statement_count);
+			snprintf(new_label, BUF_SIZE, "for-%s-%d", label, control_statement_count);
 			for_init = new_prio();
 			for_inc = new_prio();
 			for_test = new_prio();
@@ -3338,7 +3340,7 @@
 				strp2 = strchr(p->u1.for_init, '=');
 				*(strp+1) = 0;
 				strcat(buf2,"$[");
-				strncat(buf2,strp2+1, sizeof(buf2)-strlen(strp2+1)-2);
+				strncat(buf2,strp2+1, BUF_SIZE-strlen(strp2+1)-2);
 				strcat(buf2,"]");
 				for_init->appargs = strdup(buf2);
 				/* for_init->app = strdup("Set"); just set! */
@@ -3390,7 +3392,7 @@
 				strp2 = strchr(p->u3.for_inc, '=');
 				*(strp+1) = 0;
 				strcat(buf2,"$[");
-				strncat(buf2,strp2+1, sizeof(buf2)-strlen(strp2+1)-2);
+				strncat(buf2,strp2+1, BUF_SIZE-strlen(strp2+1)-2);
 				strcat(buf2,"]");
 				for_inc->appargs = strdup(buf2);
 				for_inc->app = strdup("Set");
@@ -3431,11 +3433,11 @@
 					}
 				}
 			}
-			snprintf(buf1,sizeof(buf1),"$[%s]",p->u2.for_test);
+			snprintf(buf1, BUF_SIZE, "$[%s]",p->u2.for_test);
 			for_test->app = 0;
 			for_test->appargs = strdup(buf1);
 			for_loop->goto_true = for_test;
-			snprintf(buf1,sizeof(buf1),"Finish for-%s-%d", label, control_statement_count);
+			snprintf(buf1, BUF_SIZE, "Finish for-%s-%d", label, control_statement_count);
 			for_end->app = strdup("NoOp");
 			for_end->appargs = strdup(buf1);
 			/* link & load! */
@@ -3464,7 +3466,7 @@
 			control_statement_count++;
 			loop_break_save = exten->loop_break; /* save them, then restore before leaving */
 			loop_continue_save = exten->loop_continue;
-			snprintf(new_label,sizeof(new_label),"while-%s-%d", label, control_statement_count);
+			snprintf(new_label, BUF_SIZE, "while-%s-%d", label, control_statement_count);
 			while_test = new_prio();
 			while_loop = new_prio();
 			while_end = new_prio();
@@ -3472,11 +3474,11 @@
 			while_test->goto_false = while_end;
 			while_loop->type = AEL_CONTROL1; /* simple goto */
 			while_end->type = AEL_APPCALL;
-			snprintf(buf1,sizeof(buf1),"$[%s]",p->u1.str);
+			snprintf(buf1, BUF_SIZE, "$[%s]",p->u1.str);
 			while_test->app = 0;
 			while_test->appargs = strdup(buf1);
 			while_loop->goto_true = while_test;
-			snprintf(buf1,sizeof(buf1),"Finish while-%s-%d", label, control_statement_count);
+			snprintf(buf1, BUF_SIZE, "Finish while-%s-%d", label, control_statement_count);
 			while_end->app = strdup("NoOp");
 			while_end->appargs = strdup(buf1);
 
@@ -3504,18 +3506,18 @@
 			local_control_statement_count = control_statement_count;
 			loop_break_save = exten->loop_break; /* save them, then restore before leaving */
 			loop_continue_save = exten->loop_continue;
-			snprintf(new_label,sizeof(new_label),"sw-%s-%d", label, control_statement_count);
+			snprintf(new_label, BUF_SIZE, "sw-%s-%d", label, control_statement_count);
 			switch_test = new_prio();
 			switch_end = new_prio();
 			switch_test->type = AEL_APPCALL;
 			switch_end->type = AEL_APPCALL;
-			strncpy(buf2,p->u1.str,sizeof(buf2));
-			buf2[sizeof(buf2)-1] = 0; /* just in case */
+			strncpy(buf2, p->u1.str, BUF_SIZE);
+			buf2[BUF_SIZE-1] = 0; /* just in case */
 			substitute_commas(buf2);
-			snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",control_statement_count, buf2);
+			snprintf(buf1, BUF_SIZE, "sw-%d-%s|10",control_statement_count, buf2);
 			switch_test->app = strdup("Goto");
 			switch_test->appargs = strdup(buf1);
-			snprintf(buf1,sizeof(buf1),"Finish switch-%s-%d", label, control_statement_count);
+			snprintf(buf1, BUF_SIZE, "Finish switch-%s-%d", label, control_statement_count);
 			switch_end->app = strdup("NoOp");
 			switch_end->appargs = strdup(buf1);
 			switch_end->origin = p;
@@ -3548,12 +3550,12 @@
 					switch_case->loop_continue = exten->loop_continue;
 					
 					linkexten(exten,switch_case);
-					strncpy(buf2,p2->u1.str,sizeof(buf2));
-					buf2[sizeof(buf2)-1] = 0; /* just in case */
+					strncpy(buf2,p2->u1.str, BUF_SIZE);
+					buf2[BUF_SIZE-1] = 0; /* just in case */
 					substitute_commas(buf2);
-					snprintf(buf1,sizeof(buf1),"sw-%d-%s", local_control_statement_count, buf2);
+					snprintf(buf1, BUF_SIZE, "sw-%d-%s", local_control_statement_count, buf2);
 					switch_case->name = strdup(buf1);
-					snprintf(new_label,sizeof(new_label),"sw-%s-%s-%d", label, buf2, local_control_statement_count);
+					snprintf(new_label, BUF_SIZE, "sw-%s-%s-%d", label, buf2, local_control_statement_count);
 					
 					if (gen_prios(switch_case, new_label, p2->u2.statements, exten, this_context)) { /* this will link in all the case body statements here */
 						return -1;
@@ -3571,10 +3573,10 @@
 							fall_thru = new_prio();
 							fall_thru->type = AEL_APPCALL;
 							fall_thru->app = strdup("Goto");
-							strncpy(buf2,p2->next->u1.str,sizeof(buf2));
-							buf2[sizeof(buf2)-1] = 0; /* just in case */
+							strncpy(buf2, p2->next->u1.str, BUF_SIZE);
+							buf2[BUF_SIZE-1] = 0; /* just in case */
 							substitute_commas(buf2);
-							snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
+							snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
 							fall_thru->appargs = strdup(buf1);
 							linkprio(switch_case, fall_thru, mother_exten);
 						} else if (p2->next && p2->next->type == PV_PATTERN) {
@@ -3583,14 +3585,14 @@
 							fall_thru->app = strdup("Goto");
 							gen_match_to_pattern(p2->next->u1.str, buf2);
 							substitute_commas(buf2);
-							snprintf(buf1,sizeof(buf1),"sw-%d-%s|10", local_control_statement_count, buf2);
+							snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
 							fall_thru->appargs = strdup(buf1);
 							linkprio(switch_case, fall_thru, mother_exten);
 						} else if (p2->next && p2->next->type == PV_DEFAULT) {
 							fall_thru = new_prio();
 							fall_thru->type = AEL_APPCALL;
 							fall_thru->app = strdup("Goto");
-							snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
+							snprintf(buf1, BUF_SIZE, "sw-%d-.|10",local_control_statement_count);
 							fall_thru->appargs = strdup(buf1);
 							linkprio(switch_case, fall_thru, mother_exten);
 						} else if (!p2->next) {
@@ -3606,7 +3608,7 @@
 						struct ael_priority *np2 = new_prio();
 						np2->type = AEL_APPCALL;
 						np2->app = strdup("NoOp");
-						snprintf(buf,sizeof(buf),"End of Extension %s", switch_case->name);
+						snprintf(buf, BUF_SIZE, "End of Extension %s", switch_case->name);
 						np2->appargs = strdup(buf);
 						linkprio(switch_case, np2, mother_exten);
 						switch_case-> return_target = np2;
@@ -3629,12 +3631,12 @@
 					switch_case->loop_continue = exten->loop_continue;
 					
 					linkexten(exten,switch_case);
-					strncpy(buf2,p2->u1.str,sizeof(buf2));
-					buf2[sizeof(buf2)-1] = 0; /* just in case */
+					strncpy(buf2, p2->u1.str, BUF_SIZE);
+					buf2[BUF_SIZE-1] = 0; /* just in case */
 					substitute_commas(buf2);
-					snprintf(buf1,sizeof(buf1),"_sw-%d-%s", local_control_statement_count, buf2);
+					snprintf(buf1, BUF_SIZE, "_sw-%d-%s", local_control_statement_count, buf2);
 					switch_case->name = strdup(buf1);
-					snprintf(new_label,sizeof(new_label),"sw-%s-%s-%d", label, buf2, local_control_statement_count);
+					snprintf(new_label, BUF_SIZE, "sw-%s-%s-%d", label, buf2, local_control_statement_count);
 					
 					if (gen_prios(switch_case, new_label, p2->u2.statements, exten, this_context)) { /* this will link in all the while body statements here */
 						return -1;
@@ -3651,10 +3653,10 @@
 							fall_thru = new_prio();
 							fall_thru->type = AEL_APPCALL;
 							fall_thru->app = strdup("Goto");
-							strncpy(buf2,p2->next->u1.str,sizeof(buf2));
-							buf2[sizeof(buf2)-1] = 0; /* just in case */
+							strncpy(buf2, p2->next->u1.str, BUF_SIZE);
+							buf2[BUF_SIZE-1] = 0; /* just in case */
 							substitute_commas(buf2);
-							snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
+							snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
 							fall_thru->appargs = strdup(buf1);
 							linkprio(switch_case, fall_thru, mother_exten);
 						} else if (p2->next && p2->next->type == PV_PATTERN) {
@@ -3663,14 +3665,14 @@
 							fall_thru->app = strdup("Goto");
 							gen_match_to_pattern(p2->next->u1.str, buf2);
 							substitute_commas(buf2);
-							snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
+							snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
 							fall_thru->appargs = strdup(buf1);
 							linkprio(switch_case, fall_thru, mother_exten);
 						} else if (p2->next && p2->next->type == PV_DEFAULT) {
 							fall_thru = new_prio();
 							fall_thru->type = AEL_APPCALL;
 							fall_thru->app = strdup("Goto");
-							snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
+							snprintf(buf1, BUF_SIZE, "sw-%d-.|10", local_control_statement_count);
 							fall_thru->appargs = strdup(buf1);
 							linkprio(switch_case, fall_thru, mother_exten);
 						} else if (!p2->next) {
@@ -3722,11 +3724,11 @@
 					switch_null->context = this_context;
 					switch_null->is_switch = 1;
 					switch_empty = new_prio();
-					snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
+					snprintf(buf1, BUF_SIZE, "sw-%d-.|10", local_control_statement_count);
 					switch_empty->app = strdup("Goto");
 					switch_empty->appargs = strdup(buf1);
 					linkprio(switch_null, switch_empty, mother_exten);
-					snprintf(buf1,sizeof(buf1),"sw-%d-", local_control_statement_count);
+					snprintf(buf1, BUF_SIZE, "sw-%d-", local_control_statement_count);
 					switch_null->name = strdup(buf1);
 					switch_null->loop_break = exten->loop_break;
 					switch_null->loop_continue = exten->loop_continue;
@@ -3736,10 +3738,10 @@
 					switch_case->loop_break = exten->loop_break;
 					switch_case->loop_continue = exten->loop_continue;
 					linkexten(exten,switch_case);
-					snprintf(buf1,sizeof(buf1),"_sw-%d-.", local_control_statement_count);
+					snprintf(buf1, BUF_SIZE, "_sw-%d-.", local_control_statement_count);
 					switch_case->name = strdup(buf1);
 					
-					snprintf(new_label,sizeof(new_label),"sw-%s-default-%d", label, local_control_statement_count);
+					snprintf(new_label, BUF_SIZE, "sw-%s-default-%d", label, local_control_statement_count);
 					
 					if (gen_prios(switch_case, new_label, p2->u2.statements, exten, this_context)) { /* this will link in all the default:  body statements here */
 						return -1;
@@ -3757,10 +3759,10 @@
 							fall_thru = new_prio();
 							fall_thru->type = AEL_APPCALL;
 							fall_thru->app = strdup("Goto");
-							strncpy(buf2,p2->next->u1.str,sizeof(buf2));
-							buf2[sizeof(buf2)-1] = 0; /* just in case */
+							strncpy(buf2, p2->next->u1.str, BUF_SIZE);
+							buf2[BUF_SIZE-1] = 0; /* just in case */
 							substitute_commas(buf2);
-							snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
+							snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
 							fall_thru->appargs = strdup(buf1);
 							linkprio(switch_case, fall_thru, mother_exten);
 						} else if (p2->next && p2->next->type == PV_PATTERN) {
@@ -3769,14 +3771,14 @@
 							fall_thru->app = strdup("Goto");
 							gen_match_to_pattern(p2->next->u1.str, buf2);
 							substitute_commas(buf2);
-							snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
+							snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
 							fall_thru->appargs = strdup(buf1);
 							linkprio(switch_case, fall_thru, mother_exten);
 						} else if (p2->next && p2->next->type == PV_DEFAULT) {
 							fall_thru = new_prio();
 							fall_thru->type = AEL_APPCALL;
 							fall_thru->app = strdup("Goto");
-							snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
+							snprintf(buf1, BUF_SIZE, "sw-%d-.|10", local_control_statement_count);
 							fall_thru->appargs = strdup(buf1);
 							linkprio(switch_case, fall_thru, mother_exten);
 						} else if (!p2->next) {
@@ -3811,7 +3813,7 @@
 		case PV_MACRO_CALL:
 			pr = new_prio();
 			pr->type = AEL_APPCALL;
-			snprintf(buf1,sizeof(buf1),"%s", p->u1.str);
+			snprintf(buf1, BUF_SIZE, "%s", p->u1.str);
 			for (p2 = p->u2.arglist; p2; p2 = p2->next) {
 				strcat(buf1,"|");
 				strcat(buf1,p2->u1.str);
@@ -3867,10 +3869,10 @@
 #ifdef OLD_RAND_ACTION
 		case PV_RANDOM:
 			control_statement_count++;
-			snprintf(new_label,sizeof(new_label),"rand-%s-%d", label, control_statement_count);
+			snprintf(new_label, BUF_SIZE, "rand-%s-%d", label, control_statement_count);
 			rand_test = new_prio();
 			rand_test->type = AEL_RAND_CONTROL;
-			snprintf(buf1,sizeof(buf1),"$[%s]",
+			snprintf(buf1, BUF_SIZE, "$[%s]",
 					 p->u1.str );
 			rand_test->app = 0;
 			rand_test->appargs = strdup(buf1);
@@ -3878,7 +3880,7 @@
 			
 			rand_end = new_prio();
 			rand_end->type = AEL_APPCALL;
-			snprintf(buf1,sizeof(buf1),"Finish rand-%s-%d", label, control_statement_count);
+			snprintf(buf1, BUF_SIZE, "Finish rand-%s-%d", label, control_statement_count);
 			rand_end->app = strdup("NoOp");
 			rand_end->appargs = strdup(buf1);
 			
@@ -3910,11 +3912,11 @@
 
 		case PV_IFTIME:
 			control_statement_count++;
-			snprintf(new_label,sizeof(new_label),"iftime-%s-%d", label, control_statement_count);
+			snprintf(new_label, BUF_SIZE, "iftime-%s-%d", label, control_statement_count);
 			
 			if_test = new_prio();
 			if_test->type = AEL_IFTIME_CONTROL;
-			snprintf(buf1,sizeof(buf1),"%s|%s|%s|%s",
+			snprintf(buf1, BUF_SIZE, "%s|%s|%s|%s",
 					 p->u1.list->u1.str, 
 					 p->u1.list->next->u1.str, 
 					 p->u1.list->next->next->u1.str, 
@@ -3925,7 +3927,7 @@
 
 			if_end = new_prio();
 			if_end->type = AEL_APPCALL;
-			snprintf(buf1,sizeof(buf1),"Finish iftime-%s-%d", label, control_statement_count);
+			snprintf(buf1, BUF_SIZE, "Finish iftime-%s-%d", label, control_statement_count);
 			if_end->app = strdup("NoOp");
 			if_end->appargs = strdup(buf1);
 
@@ -3973,24 +3975,24 @@
 		case PV_RANDOM:
 		case PV_IF:
 			control_statement_count++;
-			snprintf(new_label,sizeof(new_label),"if-%s-%d", label, control_statement_count);
+			snprintf(new_label, BUF_SIZE, "if-%s-%d", label, control_statement_count);
 			
 			if_test = new_prio();
 			if_end = new_prio();
 			if_test->type = AEL_IF_CONTROL;
 			if_end->type = AEL_APPCALL;
 			if ( p->type == PV_RANDOM )
-				snprintf(buf1,sizeof(buf1),"$[${RAND(0|99)} < (%s)]",p->u1.str);
+				snprintf(buf1, BUF_SIZE, "$[${RAND(0|99)} < (%s)]", p->u1.str);
 			else {
 				char buf[8000];
 				strcpy(buf,p->u1.str);
 				substitute_commas(buf);
-				snprintf(buf1,sizeof(buf1),"$[%s]",buf);
+				snprintf(buf1, BUF_SIZE, "$[%s]",buf);
 			}
 			
 			if_test->app = 0;
 			if_test->appargs = strdup(buf1);
-			snprintf(buf1,sizeof(buf1),"Finish if-%s-%d", label, control_statement_count);
+			snprintf(buf1, BUF_SIZE, "Finish if-%s-%d", label, control_statement_count);
 			if_end->app = strdup("NoOp");
 			if_end->appargs = strdup(buf1);
 			if_test->origin = p;
@@ -4048,7 +4050,7 @@
 			switch_case->context = this_context;
 			linkexten(exten,switch_case);
 			switch_case->name = strdup(p->u1.str);
-			snprintf(new_label,sizeof(new_label),"catch-%s-%d",p->u1.str, control_statement_count);
+			snprintf(new_label, BUF_SIZE, "catch-%s-%d",p->u1.str, control_statement_count);
 			
 			if (gen_prios(switch_case, new_label, p->u2.statements,mother_exten,this_context)) { /* this will link in all the catch body statements here */
 				return -1;




More information about the svn-commits mailing list