[asterisk-commits] rizzo: trunk r48389 - /trunk/main/manager.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Dec 11 11:11:58 MST 2006


Author: rizzo
Date: Mon Dec 11 12:11:58 2006
New Revision: 48389

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48389
Log:
make sure the argument to ast_malloc() is > 0.

Long explaination:

The behaviour of the underlying malloc(0) differs depending on the
operating system.  Some return NULL (SysV behaviour); some still
allocate a small chunk of memory and return a valid pointer (e.g.
traditional BSD); some (e.g. FreeBSD 6.x) return a non-null pointer
that causes a memory fault if used, even just for reading.

Given the above variety, better never call malloc(0).


Modified:
    trunk/main/manager.c

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=48389&r1=48388&r2=48389
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Mon Dec 11 12:11:58 2006
@@ -2599,7 +2599,7 @@
 		else if (strchr("&\"<>", in[x]))
 			escaped++;
 	}
-	len = (size_t) (strlen(in) + colons * 5 + breaks * (40 + strlen(dest) + strlen(objtype)) + escaped * 10); /* foo="bar", "<response type=\"object\" id=\"dest\"", "&amp;" */
+	len = (size_t) (1 + strlen(in) + colons * 5 + breaks * (40 + strlen(dest) + strlen(objtype)) + escaped * 10); /* foo="bar", "<response type=\"object\" id=\"dest\"", "&amp;" */
 	out = ast_malloc(len);
 	if (!out)
 		return NULL;



More information about the asterisk-commits mailing list