From: Matthew Jordan Date: Fri, 15 Feb 2013 23:23:49 +0000 (+0000) Subject: Fix crash in PresenceState AMI action when specifying an invalid provider X-Git-Tag: 11.4.0-rc1~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31d1bd4cd8388550492003b9f98e9795e3b75c1c;p=thirdparty%2Fasterisk.git 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 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@381594 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/funcs/func_presencestate.c b/funcs/func_presencestate.c index e62cf7d0d0..51df750982 100644 --- a/funcs/func_presencestate.c +++ b/funcs/func_presencestate.c @@ -243,7 +243,7 @@ static enum ast_presence_state custom_presence_callback(const char *data, char * ast_db_get(astdb_family, data, buf, sizeof(buf)); if (parse_data(buf, &state, &_subtype, &_message, &_options)) { - return -1; + return AST_PRESENCE_INVALID; } if ((strchr(_options, 'e'))) { @@ -252,7 +252,6 @@ static enum ast_presence_state custom_presence_callback(const char *data, char * *subtype = NULL; } else { memset(tmp, 0, sizeof(tmp)); - ast_log(LOG_NOTICE, "Hey there, I'm doing some base64 decoding\n"); ast_base64decode((unsigned char *) tmp, _subtype, sizeof(tmp) - 1); *subtype = ast_strdup(tmp); } @@ -261,12 +260,10 @@ static enum ast_presence_state custom_presence_callback(const char *data, char * *message = NULL; } else { memset(tmp, 0, sizeof(tmp)); - ast_log(LOG_NOTICE, "Hey there, I'm doing some more base64 decoding\n"); ast_base64decode((unsigned char *) tmp, _message, sizeof(tmp) - 1); *message = ast_strdup(tmp); } } else { - ast_log(LOG_NOTICE, "Not doing any base64 decoding\n"); *subtype = ast_strlen_zero(_subtype) ? NULL : ast_strdup(_subtype); *message = ast_strlen_zero(_message) ? NULL : ast_strdup(_message); } diff --git a/main/manager.c b/main/manager.c index 3572a917a1..7a9ea64d11 100644 --- a/main/manager.c +++ b/main/manager.c @@ -2248,6 +2248,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; @@ -2257,8 +2258,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) @@ -3346,7 +3352,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; } @@ -4578,6 +4584,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), diff --git a/main/presencestate.c b/main/presencestate.c index 94d0dc64dd..b87b09242c 100644 --- a/main/presencestate.c +++ b/main/presencestate.c @@ -159,6 +159,9 @@ static enum ast_presence_state ast_presence_state_helper(const char *presence_pr } AST_RWLIST_UNLOCK(&presence_state_providers); + if (!provider) { + ast_log(LOG_WARNING, "No provider found for label %s\n", label); + } return res; }