Truncate userevents at the end of a line, when the command exceeds the buffer.

(closes issue #14278)
 Reported by: fnordian


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@169364 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher
2009-01-19 19:49:25 +00:00
parent ece7a8f9e9
commit f311539733
2 changed files with 14 additions and 5 deletions

View File

@@ -2142,11 +2142,15 @@ static int action_userevent(struct mansession *s, const struct message *m)
{
const char *event = astman_get_header(m, "UserEvent");
char body[2048] = "";
int x, bodylen = 0;
int x, bodylen = 0, xlen;
for (x = 0; x < m->hdrcount; x++) {
if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:"))) {
if (sizeof(body) < bodylen + (xlen = strlen(m->headers[x])) + 3) {
ast_log(LOG_WARNING, "UserEvent exceeds our buffer length. Truncating.\n");
break;
}
ast_copy_string(body + bodylen, m->headers[x], sizeof(body) - bodylen - 3);
bodylen += strlen(m->headers[x]);
bodylen += xlen;
ast_copy_string(body + bodylen, "\r\n", 3);
bodylen += 2;
}