[Asterisk-code-review] core_local: Fix local channel parsing with slashes (asterisk[master])

N A asteriskteam at digium.com
Fri Apr 8 18:21:23 CDT 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18369 )


Change subject: core_local: Fix local channel parsing with slashes
......................................................................

core_local: Fix local channel parsing with slashes

Currently, trying to call a Local channel with a slash
in the extension will fail due to the parsing of characters
after such a slash as being dial modifiers. Additionally,
core_local is inconsistent and incomplete with
its parsing of Local dial strings in that sometimes it
uses the first slash and at other times it uses the last.

This creates inconsistent behavior for users, since using
a slash in an extension is perfectly acceptable, and using
a Goto to accomplish this works fine, but if specified
through a Local channel, the parsing prevents this.

This fixes this and improves the consistency of the dial
string parsing to always check for options after the last
slash in the dial string and only treat them as options if,
in fact, they are actually options; otherwise, it will leave
them alone.

ASTERISK-30013 #close

Change-Id: I8e85bc14072e452d0537a801aba17779569d0360
---
M main/core_local.c
1 file changed, 40 insertions(+), 16 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/69/18369/1

diff --git a/main/core_local.c b/main/core_local.c
index 26b1ba1..4436a9b 100644
--- a/main/core_local.c
+++ b/main/core_local.c
@@ -304,6 +304,24 @@
 	return peer;
 }
 
+/*! \brief Determine if text after a '/' is really options or just part of the exten */
+static int really_local_options(char *data)
+{
+	char *ptr = data;
+	if (strlen(ptr) > 4) {
+		return 0;
+	}
+	while (*ptr) {
+		/* b option no longer exists, but accept it for this purpose for compatibility */
+		if (*ptr != '/' && *ptr != 'n' && *ptr != 'j' && *ptr != 'm' && *ptr != 'b') {
+			return 0;
+		}
+		ptr++;
+	}
+	/* Okay, fine, these are definitely options... */
+	return 1;
+}
+
 /*! \brief Adds devicestate to local channels */
 static int local_devicestate(const char *data)
 {
@@ -316,8 +334,8 @@
 	struct ao2_iterator it;
 
 	/* Strip options if they exist */
-	opts = strchr(exten, '/');
-	if (opts) {
+	opts = strrchr(exten, '/');
+	if (opts && really_local_options(opts)) {
 		*opts = '\0';
 	}
 
@@ -713,7 +731,7 @@
 	 * that off for our argument to setting up the CC_INTERFACES
 	 * variable.
 	 */
-	if ((slash = strrchr(reduced_dest, '/'))) {
+	if ((slash = strrchr(reduced_dest, '/')) && really_local_options(slash)) {
 		*slash = '\0';
 	}
 	ast_set_cc_interfaces_chanvar(chan, reduced_dest);
@@ -885,20 +903,26 @@
 	ast_set_flag(&pvt->base, AST_UNREAL_MOH_INTERCEPT);
 
 	/* Look for options */
-	if ((opts = strchr(parse, '/'))) {
-		*opts++ = '\0';
-		if (strchr(opts, 'n')) {
-			ast_set_flag(&pvt->base, AST_UNREAL_NO_OPTIMIZATION);
-		}
-		if (strchr(opts, 'j')) {
-			if (ast_test_flag(&pvt->base, AST_UNREAL_NO_OPTIMIZATION)) {
-				ast_set_flag(&pvt->base.jb_conf, AST_JB_ENABLED);
-			} else {
-				ast_log(LOG_ERROR, "You must use the 'n' option with the 'j' option to enable the jitter buffer\n");
+	if ((opts = strrchr(parse, '/'))) {
+		/* The stuff after the slash might actually be part of the exten, not options. If so, don't lop them off. */
+		if (really_local_options(opts)) {
+			*opts++ = '\0';
+			if (strchr(opts, 'n')) {
+				ast_set_flag(&pvt->base, AST_UNREAL_NO_OPTIMIZATION);
 			}
-		}
-		if (strchr(opts, 'm')) {
-			ast_clear_flag(&pvt->base, AST_UNREAL_MOH_INTERCEPT);
+			if (strchr(opts, 'j')) {
+				if (ast_test_flag(&pvt->base, AST_UNREAL_NO_OPTIMIZATION)) {
+					ast_set_flag(&pvt->base.jb_conf, AST_JB_ENABLED);
+				} else {
+					ast_log(LOG_ERROR, "You must use the 'n' option with the 'j' option to enable the jitter buffer\n");
+				}
+			}
+			if (strchr(opts, 'm')) {
+				ast_clear_flag(&pvt->base, AST_UNREAL_MOH_INTERCEPT);
+			}
+		} else {
+			/* This isn't any kind of problem. Slashes are okay in the extension. */
+			ast_debug(3, "Local dial string '%s' contains slash, but no options detected\n", parse);
 		}
 	}
 

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I8e85bc14072e452d0537a801aba17779569d0360
Gerrit-Change-Number: 18369
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220408/5df684ad/attachment.html>


More information about the asterisk-code-review mailing list