<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8931">View Change</a></p><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;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/31/8931/1</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 5c50a9f..3aee5b0 100644<br>--- a/apps/app_macro.c<br>+++ b/apps/app_macro.c<br>@@ -38,6 +38,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>@@ -187,11 +188,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_include *i;<br> struct ast_context *c2;<br>+<br>+ if (iter >= AST_PBX_MAX_STACK) {<br>+ if (!(*had_error)) {<br>+ *had_error = 1;<br>+ ast_log(LOG_ERROR, "Potential infinate 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>@@ -213,7 +223,7 @@<br> for (i=ast_walk_context_includes(c, NULL); i; i=ast_walk_context_includes(c, i)) {<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>@@ -250,6 +260,7 @@<br> char *save_macro_offset;<br> int save_in_subroutine;<br> struct ast_datastore *macro_store = ast_channel_datastore_find(chan, ¯o_ds_info, NULL);<br>+ int had_infinite_include_error = 0;<br> <br> if (ast_strlen_zero(data)) {<br> ast_log(LOG_WARNING, "Macro() requires arguments. See \"core show application macro\" for help.\n");<br>@@ -418,7 +429,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/8931">change 8931</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/8931"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I6c71b76998c31434391b150de055ae9a531e31da </div>
<div style="display:none"> Gerrit-Change-Number: 8931 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>