[asterisk-commits] russell: branch 1.6.1 r176903 - in /branches/1.6.1: ./ main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 18 00:05:09 CST 2009


Author: russell
Date: Wed Feb 18 00:05:09 2009
New Revision: 176903

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=176903
Log:
Merged revisions 176901 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
r176901 | russell | 2009-02-18 00:00:40 -0600 (Wed, 18 Feb 2009) | 9 lines

Fix a number of incorrect uses of strncpy().

The big problem here is that the 3rd argument provided in these uses of strncpy()
did not reserve a byte for the null terminator, leaving the potential for writing
one byte past the end of the buffer.

Aside from this, there were coding guidelines violations with regards to spacing,
as well as hard coded lengths being used instead of sizeof().

........

Modified:
    branches/1.6.1/   (props changed)
    branches/1.6.1/main/pbx.c

Propchange: branches/1.6.1/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.1/main/pbx.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.6.1/main/pbx.c?view=diff&rev=176903&r1=176902&r2=176903
==============================================================================
--- branches/1.6.1/main/pbx.c (original)
+++ branches/1.6.1/main/pbx.c Wed Feb 18 00:05:09 2009
@@ -1469,7 +1469,8 @@
 	int l1 = strlen(e1->exten) + strlen(e1->cidmatch) + 2;
 	
 
-	strncpy(extenbuf,e1->exten,sizeof(extenbuf));
+	ast_copy_string(extenbuf, e1->exten, sizeof(extenbuf));
+
 	if (e1->matchcid &&  l1 <= sizeof(extenbuf)) {
 		strcat(extenbuf,"/");
 		strcat(extenbuf,e1->cidmatch);
@@ -1997,7 +1998,9 @@
 {
 	struct ast_context *tmp = NULL;
 	struct fake_context item;
-	strncpy(item.name,name,256);
+
+	ast_copy_string(item.name, name, sizeof(item.name));
+
 	ast_rdlock_contexts();
 	if( contexts_table ) {
 		tmp = ast_hashtab_lookup(contexts_table,&item);
@@ -2069,8 +2072,10 @@
 		tmp = bypass;
 	else {	/* look in contexts */
 		struct fake_context item;
-		strncpy(item.name,context,256);
-		tmp = ast_hashtab_lookup(contexts_table,&item);
+
+		ast_copy_string(item.name, context, sizeof(item.name));
+
+		tmp = ast_hashtab_lookup(contexts_table, &item);
 #ifdef NOTNOW
 		tmp = NULL;
 		while ((tmp = ast_walk_contexts(tmp)) ) {
@@ -4422,7 +4427,8 @@
 
 	ast_rdlock_contexts();
 
-	strncpy(item.name,context,256);
+	ast_copy_string(item.name, context, sizeof(item.name));
+
 	c = ast_hashtab_lookup(contexts_table,&item);
 	if (c)
 		ret = 0;
@@ -4460,7 +4466,8 @@
 
 	ast_rdlock_contexts();
 
-	strncpy(item.name, context, 256);
+	ast_copy_string(item.name, context, sizeof(item.name));
+
 	c = ast_hashtab_lookup(contexts_table,&item);
 	if (c)
 		ret = 0;
@@ -5780,7 +5787,7 @@
 										   0);
 	}
 	
-	strncpy(search.name,name,sizeof(search.name));
+	ast_copy_string(search.name, name, sizeof(search.name));
 	if (!extcontexts) {
 		ast_rdlock_contexts();
 		local_contexts = &contexts;
@@ -7006,7 +7013,7 @@
 	
 	if (con->pattern_tree) { /* usually, on initial load, the pattern_tree isn't formed until the first find_exten; so if we are adding
 								an extension, and the trie exists, then we need to incrementally add this pattern to it. */
-		strncpy(dummy_name,extension,sizeof(dummy_name));
+		ast_copy_string(dummy_name, extension, sizeof(dummy_name));
 		dummy_exten.exten = dummy_name;
 		dummy_exten.matchcid = 0;
 		dummy_exten.cidmatch = 0;




More information about the asterisk-commits mailing list