[svn-commits] rmudgett: trunk r368714 - in /trunk: include/asterisk/ main/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Jun 8 16:08:21 CDT 2012
Author: rmudgett
Date: Fri Jun 8 16:08:17 2012
New Revision: 368714
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=368714
Log:
Fix error paths in action_hangup() for AMI Hangup action.
* Check allocation function return values for failure. Crashing is bad.
* Tweak ast_regex_string_to_regex_pattern() parameters for proper ast_str
usage.
Modified:
trunk/include/asterisk/strings.h
trunk/main/manager.c
trunk/main/utils.c
Modified: trunk/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/strings.h?view=diff&rev=368714&r1=368713&r2=368714
==============================================================================
--- trunk/include/asterisk/strings.h (original)
+++ trunk/include/asterisk/strings.h Fri Jun 8 16:08:17 2012
@@ -253,19 +253,19 @@
int ast_build_string_va(char **buffer, size_t *space, const char *fmt, va_list ap) __attribute__((format(printf, 3, 0)));
/*!
- \brief Given a string regex_string in the form of "/regex/", convert it into the form of "regex"
-
- This function will trim one leading / and one trailing / from a given input string
- ast_str regex_pattern must be preallocated before calling this function
-
- \return 0 on success, non-zero on failure.
- \return 1 if we only stripped a leading /
- \return 2 if we only stripped a trailing /
- \return 3 if we did not strip any / characters
- \param regex_string the string containing /regex/
- \param regex_pattern the destination ast_str which will contain "regex" after execution
-*/
-int ast_regex_string_to_regex_pattern(const char *regex_string, struct ast_str *regex_pattern);
+ * \brief Given a string regex_string in the form of "/regex/", convert it into the form of "regex"
+ *
+ * This function will trim one leading / and one trailing / from a given input string
+ * ast_str regex_pattern must be preallocated before calling this function
+ *
+ * \return 0 on success, non-zero on failure.
+ * \return 1 if we only stripped a leading /
+ * \return 2 if we only stripped a trailing /
+ * \return 3 if we did not strip any / characters
+ * \param regex_string the string containing /regex/
+ * \param regex_pattern the destination ast_str which will contain "regex" after execution
+ */
+int ast_regex_string_to_regex_pattern(const char *regex_string, struct ast_str **regex_pattern);
/*!
* \brief Make sure something is true.
Modified: trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/manager.c?view=diff&rev=368714&r1=368713&r2=368714
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Fri Jun 8 16:08:17 2012
@@ -3199,7 +3199,7 @@
const char *id = astman_get_header(m, "ActionID");
const char *name_or_regex = astman_get_header(m, "Channel");
const char *cause = astman_get_header(m, "Cause");
- char idText[256] = "";
+ char idText[256];
regex_t regexbuf;
struct ast_channel_iterator *iter = NULL;
struct ast_str *regex_string;
@@ -3212,6 +3212,8 @@
if (!ast_strlen_zero(id)) {
snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
+ } else {
+ idText[0] = '\0';
}
if (!ast_strlen_zero(cause)) {
@@ -3252,9 +3254,13 @@
/* find and hangup any channels matching regex */
regex_string = ast_str_create(strlen(name_or_regex));
+ if (!regex_string) {
+ astman_send_error(s, m, "Memory Allocation Failure");
+ return 0;
+ }
/* Make "/regex/" into "regex" */
- if (ast_regex_string_to_regex_pattern(name_or_regex, regex_string) != 0) {
+ if (ast_regex_string_to_regex_pattern(name_or_regex, ®ex_string) != 0) {
astman_send_error(s, m, "Regex format invalid, Channel param should be /regex/");
ast_free(regex_string);
return 0;
@@ -3269,31 +3275,31 @@
astman_send_listack(s, m, "Channels hung up will follow", "start");
- for (iter = ast_channel_iterator_all_new(); iter && (c = ast_channel_iterator_next(iter)); ) {
- if (regexec(®exbuf, ast_channel_name(c), 0, NULL, 0)) {
- ast_channel_unref(c);
- continue;
- }
-
- ast_verb(3, "%sManager '%s' from %s, hanging up channel: %s\n",
- (s->session->managerid ? "HTTP " : ""),
- s->session->username,
- ast_inet_ntoa(s->session->sin.sin_addr),
- ast_channel_name(c));
-
- ast_channel_softhangup_withcause_locked(c, causecode);
- channels_matched++;
-
- astman_append(s,
- "Event: ChannelHungup\r\n"
- "Channel: %s\r\n"
- "%s"
- "\r\n", ast_channel_name(c), idText);
-
- ast_channel_unref(c);
- }
-
- ast_channel_iterator_destroy(iter);
+ iter = ast_channel_iterator_all_new();
+ if (iter) {
+ for (; (c = ast_channel_iterator_next(iter)); ast_channel_unref(c)) {
+ if (regexec(®exbuf, ast_channel_name(c), 0, NULL, 0)) {
+ continue;
+ }
+
+ ast_verb(3, "%sManager '%s' from %s, hanging up channel: %s\n",
+ (s->session->managerid ? "HTTP " : ""),
+ s->session->username,
+ ast_inet_ntoa(s->session->sin.sin_addr),
+ ast_channel_name(c));
+
+ ast_channel_softhangup_withcause_locked(c, causecode);
+ channels_matched++;
+
+ astman_append(s,
+ "Event: ChannelHungup\r\n"
+ "Channel: %s\r\n"
+ "%s"
+ "\r\n", ast_channel_name(c), idText);
+ }
+ ast_channel_iterator_destroy(iter);
+ }
+
regfree(®exbuf);
ast_free(regex_string);
Modified: trunk/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/utils.c?view=diff&rev=368714&r1=368713&r2=368714
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Fri Jun 8 16:08:17 2012
@@ -1362,20 +1362,20 @@
return result;
}
-int ast_regex_string_to_regex_pattern(const char *regex_string, struct ast_str *regex_pattern)
+int ast_regex_string_to_regex_pattern(const char *regex_string, struct ast_str **regex_pattern)
{
int regex_len = strlen(regex_string);
int ret = 3;
/* Chop off the leading / if there is one */
if ((regex_len >= 1) && (regex_string[0] == '/')) {
- ast_str_set(®ex_pattern, 0, "%s", regex_string + 1);
+ ast_str_set(regex_pattern, 0, "%s", regex_string + 1);
ret -= 2;
}
/* Chop off the ending / if there is one */
if ((regex_len > 1) && (regex_string[regex_len - 1] == '/')) {
- ast_str_truncate(regex_pattern, -1);
+ ast_str_truncate(*regex_pattern, -1);
ret -= 1;
}
More information about the svn-commits
mailing list