[asterisk-commits] tilghman: trunk r72557 - in /trunk: ./ main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 28 23:56:09 CDT 2007


Author: tilghman
Date: Thu Jun 28 23:56:08 2007
New Revision: 72557

URL: http://svn.digium.com/view/asterisk?view=rev&rev=72557
Log:
Merged revisions 72556 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r72556 | tilghman | 2007-06-28 23:47:11 -0500 (Thu, 28 Jun 2007) | 2 lines

Issue 10055 - Change memory allocation to use the heap for a command, since the output has the potential to overflow the stack (as it did here)

........

Modified:
    trunk/   (props changed)
    trunk/main/manager.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=72557&r1=72556&r2=72557
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Thu Jun 28 23:56:08 2007
@@ -1847,17 +1847,26 @@
 	/* FIXME: Wedge a ActionID response in here, waiting for later changes */
 	ast_cli_command(fd, cmd);	/* XXX need to change this to use a FILE * */
 	l = lseek(fd, 0, SEEK_END);	/* how many chars available */
-	buf = alloca(l + 1);
-	final_buf = alloca(l + 1);
-	lseek(fd, 0, SEEK_SET);
-	read(fd, buf, l);
-	buf[l] = '\0';
+
+	/* This has a potential to overflow the stack.  Hence, use the heap. */
+	buf = ast_calloc(1, l + 1);
+	final_buf = ast_calloc(1, l + 1);
+	if (buf) {
+		lseek(fd, 0, SEEK_SET);
+		read(fd, buf, l);
+		buf[l] = '\0';
+		if (final_buf) {
+			term_strip(final_buf, buf, l);
+			final_buf[l] = '\0';
+		}
+		astman_append(s, S_OR(final_buf, buf));
+		ast_free(buf);
+	}
 	close(fd);
 	unlink(template);
-	term_strip(final_buf, buf, l);
-	final_buf[l] = '\0';
-	astman_append(s, final_buf);
 	astman_append(s, "--END COMMAND--\r\n\r\n");
+	if (final_buf)
+		ast_free(final_buf);
 	return 0;
 }
 




More information about the asterisk-commits mailing list