aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-06-29 04:47:11 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-06-29 04:47:11 +0000
commitdab1a9e111ccc1b78a0b127bd10cad3262f19f6f (patch)
tree266218d5ab6ecafe6972b959f5189feb03ff8bcd /main
parent5582e15bd9d7cebb3b8362ccf41d4c2645963401 (diff)
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)
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@72556 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/manager.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/main/manager.c b/main/manager.c
index be77dfc94..0b20fafba 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1636,17 +1636,26 @@ static int action_command(struct mansession *s, const struct message *m)
/* 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;
}