[Asterisk-code-review] app_queue.c: Don't escape commas in MONITOR_FILENAME. (asterisk[16])

Sean Bright asteriskteam at digium.com
Sun Sep 18 16:36:18 CDT 2022


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19300 )


Change subject: app_queue.c: Don't escape commas in MONITOR_FILENAME.
......................................................................

app_queue.c: Don't escape commas in MONITOR_FILENAME.

The contents of the MONITOR_FILENAME variable is evaluated when a
queue member is connected to a caller, allowing information about the
member to be included in the filename.

This is made possible by using ^{MEMBERINTERFACE} syntax instead of
${MEMBERINTERFACE} when assigning a value to MONITOR_FILENAME so that
evaluation does not occur immediately. The MONITOR_EXEC variable is
handled similarly.

Because of the way that MONITOR_EXEC works under the hood, the code
that performs the variable replacement also escapes commas before
doing so. However, this replacement should be taking place after the
variable replacement is done so that unescaped commas are not
erroneously passed to the MixMonitor start function.

Finally, having a comma in a filename is not problematic so we now
only escape commas after variable replacement is performed on
MONITOR_EXEC.

The main consequence of this change is that you can now use dialplan
functions with multiple arguments in MONITOR_FILENAME without the
commas being escaped before variable replacement occurs.

ASTERISK-30236 #close

Change-Id: Ib18481288c5292e27321e95364d7e63e8917252f
---
M apps/app_queue.c
1 file changed, 53 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/00/19300/1

diff --git a/apps/app_queue.c b/apps/app_queue.c
index b4f3d8b..337cc71 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -6823,8 +6823,13 @@
 	}
 }
 
+enum escape_type {
+	MONITOR_FILENAME,
+	MONITOR_EXEC,
+};
+
 static void escape_and_substitute(struct ast_channel *chan, const char *input,
-		char *output, size_t size)
+		char *output, size_t size, enum escape_type type)
 {
 	const char *m = input;
 	char escaped[size];
@@ -6837,9 +6842,6 @@
 				*p = '$';
 			}
 			break;
-		case ',':
-			*p++ = '\\';
-			/* Fall through */
 		default:
 			*p = *m;
 		}
@@ -6852,6 +6854,15 @@
 	}
 
 	pbx_substitute_variables_helper(chan, escaped, output, size - 1);
+
+	if (type == MONITOR_EXEC) {
+		/* Commas are only significant to MONITOR_EXEC because of the way that we
+		   handle argument passing in ast_mixmonitor_start(). The
+		   MONITOR_FILENAME does not have the same limitation so we do not need
+		   commas escaped there. */
+		ast_escape(escaped, output, size, ",");
+		ast_copy_string(output, escaped, size);
+	}
 }
 
 static void setup_mixmonitor(struct queue_ent *qe, const char *filename)
@@ -6866,7 +6877,8 @@
 	escaped_monitor_exec[0] = '\0';
 
 	if (filename) {
-		escape_and_substitute(qe->chan, filename, escaped_filename, sizeof(escaped_filename));
+		escape_and_substitute(qe->chan, filename,
+			escaped_filename, sizeof(escaped_filename), MONITOR_FILENAME);
 	} else {
 		ast_copy_string(escaped_filename, ast_channel_uniqueid(qe->chan), sizeof(escaped_filename));
 	}
@@ -6883,7 +6895,8 @@
 	ast_channel_unlock(qe->chan);
 
 	if (monitor_exec) {
-		escape_and_substitute(qe->chan, monitor_exec, escaped_monitor_exec, sizeof(escaped_monitor_exec));
+		escape_and_substitute(qe->chan, monitor_exec,
+			escaped_monitor_exec, sizeof(escaped_monitor_exec), MONITOR_EXEC);
 	}
 
 	snprintf(file_with_ext, sizeof(file_with_ext), "%s.%s", escaped_filename, qe->parent->monfmt);

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ib18481288c5292e27321e95364d7e63e8917252f
Gerrit-Change-Number: 19300
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220918/d45f1ee7/attachment.html>


More information about the asterisk-code-review mailing list