[Asterisk-code-review] main/pbx_variables.c: Better parsing of variable name and value separ... (asterisk[16])

Leandro Dardini asteriskteam at digium.com
Sun Jan 10 16:35:50 CST 2021


Leandro Dardini has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15322 )


Change subject: main/pbx_variables.c: Better parsing of variable name and value separator for Set command
......................................................................

main/pbx_variables.c: Better parsing of variable name and value separator for Set command

The variable name and value of a Set command are separated by a =, but the = character
may appear in the variable name portion as a parameter for a function, like any ODBC_*
func_odbc.conf function, so better handling of quotes, parenthesis, and brackets was
needed.

ASTERISK-29239 #close

Change-Id: I88cd6230bfd0295a6a1c0b08d3ca37c006f561e6
---
M main/pbx_variables.c
1 file changed, 30 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/22/15322/1

diff --git a/main/pbx_variables.c b/main/pbx_variables.c
index 91b5bbb..1035ffe 100644
--- a/main/pbx_variables.c
+++ b/main/pbx_variables.c
@@ -1128,7 +1128,8 @@
 
 int pbx_builtin_setvar(struct ast_channel *chan, const char *data)
 {
-	char *name, *value, *mydata;
+	char *name = NULL, *value = NULL, *mydata, *scan;
+	int paren = 0, quote = 0, bracket = 0;
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Set requires one variable name/value pair.\n");
@@ -1136,8 +1137,34 @@
 	}
 
 	mydata = ast_strdupa(data);
-	name = strsep(&mydata, "=");
-	value = mydata;
+
+	scan = mydata;
+
+	for (; *scan; scan++) {
+          if (*scan == '(') {
+            paren++;
+          } else if (*scan == ')') {
+            if (paren) {
+              paren--;
+            }
+          } else if (*scan == '[') {
+            bracket++;
+          } else if (*scan == ']') {
+            if (bracket) {
+              bracket--;
+            }
+          } else if (*scan == '"') {
+            quote = quote ? 0 : 1;
+          } else if (*scan == '\\') {
+            scan++;
+          } else if ((*scan == '=') && !paren && !quote && !bracket) {
+            *scan++ = '\0';
+            value = scan;
+            name = mydata;
+            break;
+          }
+        }
+
 	if (!value) {
 		ast_log(LOG_WARNING, "Set requires an '=' to be a valid assignment.\n");
 		return 0;

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I88cd6230bfd0295a6a1c0b08d3ca37c006f561e6
Gerrit-Change-Number: 15322
Gerrit-PatchSet: 1
Gerrit-Owner: Leandro Dardini <ldardini at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210110/62e84dff/attachment-0001.html>


More information about the asterisk-code-review mailing list