]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
map_afrom_cp: unescape double-quoted and back-quoted RHS prior to parsing it (#4607)
authorMax Khon <fjoe@samodelkin.net>
Wed, 27 Jul 2022 14:34:45 +0000 (17:34 +0300)
committerGitHub <noreply@github.com>
Wed, 27 Jul 2022 14:34:45 +0000 (10:34 -0400)
src/lib/server/map.c
src/tests/keywords/length

index 145ac78bab6d4d7eaab773e967fba49276fda76f..bc9546f0291db552b5def220bde63980854b46a9 100644 (file)
@@ -99,6 +99,8 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
 {
        map_t           *map;
        char const      *attr, *value, *marker_subject;
+       char            *unescaped_value = NULL;
+       fr_sbuff_parse_rules_t const *p_rules;
        ssize_t         slen;
        fr_token_t      type;
 
@@ -164,16 +166,33 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
         *      RHS might be an attribute reference.
         */
        type = cf_pair_value_quote(cp);
+       p_rules = value_parse_rules_unquoted[type]; /* We're not searching for quotes */
+       if (type == T_DOUBLE_QUOTED_STRING || type == T_BACK_QUOTED_STRING) {
+               slen = fr_sbuff_out_aunescape_until(map, &unescaped_value,
+                               &FR_SBUFF_IN(value, talloc_array_length(value) - 1), SIZE_MAX, p_rules->terminals, p_rules->escapes);
+               if (slen < 0) {
+                       marker_subject = value;
+                       goto marker;
+               }
+               value = unescaped_value;
+               p_rules = NULL;
+       } else {
+               slen = talloc_array_length(value) - 1;
+       }
 
        slen = tmpl_afrom_substr(map, &map->rhs,
-                                &FR_SBUFF_IN(value, strlen(value)),
+                                &FR_SBUFF_IN(value, slen),
                                 type,
-                                value_parse_rules_unquoted[type],      /* We're not searching for quotes */
+                                p_rules,
                                 rhs_rules);
        if (slen < 0) {
                marker_subject = value;
                goto marker;
        }
+       if (unescaped_value != NULL) {
+               talloc_free(unescaped_value);
+               unescaped_value = NULL;
+       }
 
        if (!map->rhs) {
                cf_log_perr(cp, "Failed parsing RHS");
@@ -214,6 +233,10 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
        return 0;
 
 error:
+       if (unescaped_value != NULL) {
+               talloc_free(unescaped_value);
+               unescaped_value = NULL;
+       }
        talloc_free(map);
        return -1;
 }
index 157c2de0a07402aa96e523b2d8db47fd328efc29..9df97ae36b24927f949e3c987055c59e0c6104e1 100644 (file)
@@ -32,6 +32,7 @@ update request {
        &Tmp-Integer-0        := "%(length:%{Tmp-String-2})"
        &Tmp-Integer-1        := "%(length:%{Tmp-Octets-0})"
        &Tmp-Integer-2        := "%(length:%{Tmp-IP-Address-0})"
+       &Tmp-Integer-3        := "%(length:\"hello, world\")"
        &Tmp-Integer-4        := "%(length:%{Tmp-Integer-0})"
        &Tmp-Integer-6        := "%(length:%{Tmp-Cast-Ifid})"
        &Tmp-Integer-7        := "%(length:%{Tmp-Cast-IPv6Addr})"
@@ -54,6 +55,10 @@ if (&Tmp-Integer-2 != 4) {
        test_fail
 }
 
+# String - "hello, world"
+if (&Tmp-Integer-3 != 12) {
+       test_fail
+}
 
 # Integer - bin 0x39383734
 if (&Tmp-Integer-4 != 4) {