diff options
author | Matthew Jordan <mjordan@digium.com> | 2013-02-15 23:29:28 +0000 |
---|---|---|
committer | Matthew Jordan <mjordan@digium.com> | 2013-02-15 23:29:28 +0000 |
commit | c209e85ad31ac3983a0eb7684055cdd808cbd8fe (patch) | |
tree | 4ad998c53caf879cc4c99a867911731e5341bf2f /main/manager.c | |
parent | 8a7dd2f40880f988ea017294ad8001bf0e1825b5 (diff) |
Fix crash in PresenceState AMI action when specifying an invalid provider
This patch fixes a crash in Asterisk that could be caused by using the
PresenceState AMI action while providing an invalid provider. This patch
also adds some additional warnings when a user attempts to provide the
PresenceState action with invalid data, and removes some NOTICE statements
that were still lurking in the code from testing.
(closes issue AST-1084)
Reported by: John Bigelow
Tested by: John Bigelow
........
Merged revisions 381594 from http://svn.asterisk.org/svn/asterisk/branches/11
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@381595 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/manager.c')
-rw-r--r-- | main/manager.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/main/manager.c b/main/manager.c index 0543ee6fb..2c6751776 100644 --- a/main/manager.c +++ b/main/manager.c @@ -2280,6 +2280,7 @@ void astman_send_error_va(struct mansession *s, const struct message *m, const c { va_list ap; struct ast_str *buf; + char *msg; if (!(buf = ast_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE))) { return; @@ -2289,8 +2290,13 @@ void astman_send_error_va(struct mansession *s, const struct message *m, const c ast_str_set_va(&buf, 0, fmt, ap); va_end(ap); - astman_send_response_full(s, m, "Error", ast_str_buffer(buf), NULL); - ast_free(buf); + /* astman_append will use the same underlying buffer, so copy the message out + * before sending the response */ + msg = ast_str_buffer(buf); + if (msg) { + msg = ast_strdupa(msg); + } + astman_send_response_full(s, m, "Error", msg, NULL); } void astman_send_ack(struct mansession *s, const struct message *m, char *msg) @@ -3378,7 +3384,7 @@ static int action_hangup(struct mansession *s, const struct message *m) /* if regex compilation fails, hangup fails */ if (regcomp(®exbuf, ast_str_buffer(regex_string), REG_EXTENDED | REG_NOSUB)) { - astman_send_error_va(s, m, "Regex compile failed on: %s\n", name_or_regex); + astman_send_error_va(s, m, "Regex compile failed on: %s", name_or_regex); ast_free(regex_string); return 0; } @@ -4610,6 +4616,10 @@ static int action_presencestate(struct mansession *s, const struct message *m) } state = ast_presence_state(provider, &subtype, &message); + if (state == AST_PRESENCE_INVALID) { + astman_send_error_va(s, m, "Invalid provider %s or provider in invalid state", provider); + return 0; + } if (!ast_strlen_zero(subtype)) { snprintf(subtype_header, sizeof(subtype_header), |