[Asterisk-code-review] pbx.c: Warn if there are too many includes in a context. (asterisk[master])

Kevin Harwell asteriskteam at digium.com
Tue Mar 29 16:06:09 CDT 2022


Kevin Harwell has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/18188 )

Change subject: pbx.c: Warn if there are too many includes in a context.
......................................................................

pbx.c: Warn if there are too many includes in a context.

The PBX core uses the stack when it comes to includes, which
means that a context can only contain strictly fewer than
AST_PBX_MAX_STACK includes. If this is exceeded, then warnings
will be emitted for each number of includes beyond this if
searching for an extension in the including context, and if
the extension's inclusion is beyond the stack size, it will
simply not be found.

To address this, we now check if there are too many includes
in a context when the dialplan is reloaded so that if there
is an issue, the user is aware of at "compile time" as opposed
to "run time" only. Secondly, more details are printed out
when this message is encountered so it's clear what has happened.

ASTERISK-26719

Change-Id: Ia3700452e75a7af3391b3e82ee69f06a669f8958
---
M main/pbx.c
1 file changed, 8 insertions(+), 2 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved; Approved for Submit
  Benjamin Keith Ford: Looks good to me, but someone else must approve



diff --git a/main/pbx.c b/main/pbx.c
index 07cf8e7..00c653f 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -2506,7 +2506,7 @@
 		q->data = NULL;
 		q->foundcontext = NULL;
 	} else if (q->stacklen >= AST_PBX_MAX_STACK) {
-		ast_log(LOG_WARNING, "Maximum PBX stack exceeded\n");
+		ast_log(LOG_WARNING, "Maximum PBX stack (%d) exceeded. Too many includes?\n", AST_PBX_MAX_STACK);
 		return NULL;
 	}
 
@@ -8771,8 +8771,14 @@
 {
 	int idx;
 	int res = 0;
+	int includecount = ast_context_includes_count(con);
 
-	for (idx = 0; idx < ast_context_includes_count(con); idx++) {
+	if (includecount >= AST_PBX_MAX_STACK) {
+		ast_log(LOG_WARNING, "Context %s contains too many includes (%d). Maximum is %d.\n",
+			ast_get_context_name(con), includecount, AST_PBX_MAX_STACK);
+	}
+
+	for (idx = 0; idx < includecount; idx++) {
 		const struct ast_include *inc = ast_context_includes_get(con, idx);
 
 		if (ast_context_find(include_rname(inc))) {

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18188
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ia3700452e75a7af3391b3e82ee69f06a669f8958
Gerrit-Change-Number: 18188
Gerrit-PatchSet: 2
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220329/eb20f50c/attachment.html>


More information about the asterisk-code-review mailing list