]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: var-expand - handle \{ and \} correctly
authorAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 1 Dec 2017 17:46:58 +0000 (19:46 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 11 Dec 2017 11:48:57 +0000 (13:48 +0200)
Do not treat these as embedded braces

src/lib/var-expand.c

index 57c7fecda68be3b429d31cd769b8d3214ab8839f..5b07b370553d03a6881d8319bb81079ee3bb4cbd 100644 (file)
@@ -556,8 +556,17 @@ int var_expand_with_funcs(string_t *dest, const char *str,
                        if (*str == '{' && (end = strchr(str, '}')) != NULL) {
                                /* %{long_key} */
                                unsigned int ctr = 1;
+                               bool escape = FALSE;
                                end = str;
                                while(*++end != '\0' && ctr > 0) {
+                                       if (!escape && *end == '\\') {
+                                               escape = TRUE;
+                                               continue;
+                                       }
+                                       if (escape) {
+                                               escape = FALSE;
+                                               continue;
+                                       }
                                        if (*end == '{') ctr++;
                                        if (*end == '}') ctr--;
                                }
@@ -659,6 +668,14 @@ var_get_key_range_full(const char *str, unsigned int *idx_r,
                /* long key */
                *idx_r = ++i;
                for (; str[i] != '\0'; i++) {
+                       if (!escape && str[i] == '\\') {
+                               escape = TRUE;
+                               continue;
+                       }
+                       if (escape) {
+                               escape = FALSE;
+                               continue;
+                       }
                        if (str[i] == '{')
                                depth++;
                        if (str[i] == '}') {