<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/8929">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_macro: Prevent infinite loop in find_matching_priority.<br><br>Use AST_PBX_MAX_STACK to escape if we recurse 128 times.  This will<br>prevent crash if dialplan contains an include loop.  Log an error when<br>this occurs, at most one message per call to Macro() so we avoid logger<br>spam.<br><br>ASTERISK-26570 #close<br><br>Change-Id: I6c71b76998c31434391b150de055ae9a531e31da<br>---<br>M apps/app_macro.c<br>1 file changed, 16 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/apps/app_macro.c b/apps/app_macro.c<br>index de9b15c..36632dc 100644<br>--- a/apps/app_macro.c<br>+++ b/apps/app_macro.c<br>@@ -37,6 +37,7 @@<br> #include "asterisk/channel.h"<br> #include "asterisk/pbx.h"<br> #include "asterisk/module.h"<br>+#include "asterisk/extconf.h"<br> #include "asterisk/config.h"<br> #include "asterisk/utils.h"<br> #include "asterisk/lock.h"<br>@@ -186,11 +187,20 @@<br>    }<br> }<br> <br>-static struct ast_exten *find_matching_priority(struct ast_context *c, const char *exten, int priority, const char *callerid)<br>+static struct ast_exten *find_matching_priority(struct ast_context *c, const char *exten,<br>+ int priority, const char *callerid, int iter, int *had_error)<br> {<br>     struct ast_exten *e;<br>  struct ast_context *c2;<br>       int idx;<br>+<br>+  if (iter >= AST_PBX_MAX_STACK) {<br>+          if (!(*had_error)) {<br>+                 *had_error = 1;<br>+                      ast_log(LOG_ERROR, "Potential infinite loop detected, will not recurse further.\n");<br>+               }<br>+            return NULL;<br>+ }<br> <br>  for (e=ast_walk_context_extensions(c, NULL); e; e=ast_walk_context_extensions(c, e)) {<br>                if (ast_extension_match(ast_get_extension_name(e), exten)) {<br>@@ -214,7 +224,7 @@<br> <br>          for (c2=ast_walk_contexts(NULL); c2; c2=ast_walk_contexts(c2)) {<br>                      if (!strcmp(ast_get_context_name(c2), ast_get_include_name(i))) {<br>-                            e = find_matching_priority(c2, exten, priority, callerid);<br>+                           e = find_matching_priority(c2, exten, priority, callerid, iter + 1, had_error);<br>                               if (e)<br>                                        return e;<br>                     }<br>@@ -251,6 +261,7 @@<br>        char *save_macro_offset;<br>      int save_in_subroutine;<br>       struct ast_datastore *macro_store = ast_channel_datastore_find(chan, &macro_ds_info, NULL);<br>+      int had_infinite_include_error = 0;<br>   static int deprecation_notice = 0;<br> <br>         if (ast_strlen_zero(data)) {<br>@@ -426,7 +437,9 @@<br>                                             ast_log(LOG_WARNING, "Unable to lock context?\n");<br>                                  } else {<br>                                              e = find_matching_priority(c, ast_channel_exten(chan), ast_channel_priority(chan),<br>-                                                   S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));<br>+                                                      S_COR(ast_channel_caller(chan)->id.number.valid,<br>+                                                  ast_channel_caller(chan)->id.number.str, NULL),<br>+                                                   0, &had_infinite_include_error);<br>                                          if (e) { /* This will only be undefined for pbx_realtime, which is majorly broken. */<br>                                                         ast_copy_string(runningapp, ast_get_extension_app(e), sizeof(runningapp));<br>                                                    ast_copy_string(runningdata, ast_get_extension_app_data(e), sizeof(runningdata));<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8929">change 8929</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8929"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I6c71b76998c31434391b150de055ae9a531e31da </div>
<div style="display:none"> Gerrit-Change-Number: 8929 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>