]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
remove more fr_pair_list_afrom_str()
authorAlan T. DeKok <aland@freeradius.org>
Sun, 29 Oct 2023 13:46:04 +0000 (09:46 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 29 Oct 2023 13:46:04 +0000 (09:46 -0400)
src/lib/util/pair.c
src/lib/util/pair_legacy.c
src/lib/util/pair_legacy.h

index 1b2a54462a38a3ea0c2b0d8b9307429b92e1f2a8..9f2936007870b5bd5d2611019739ef81a377b3a2 100644 (file)
@@ -3552,65 +3552,26 @@ static fr_pair_t *pair_alloc_parent(fr_pair_t *in, fr_pair_t *item, fr_dict_attr
  */
 void fr_pair_list_afrom_box(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, fr_value_box_t *box)
 {
-       int comma = 0;
-       char *p, *end, *last_comma = NULL;
+       fr_pair_parse_t root, relative;
 
        fr_assert(box->type == FR_TYPE_STRING);
 
-       /*
-        *      HACK: Replace '\n' with ',' so that
-        *      fr_pair_list_afrom_str() can parse the buffer in
-        *      one go (the proper way would be to
-        *      fix fr_pair_list_afrom_str(), but oh well).
-        *
-        *      Note that we can mangle box->vb_strvalue, as it's
-        *      getting discarded immediately after this modification.
-        */
-       memcpy(&p, &box->vb_strvalue, sizeof(p)); /* const issues */
-       end = p + talloc_array_length(box->vb_strvalue) - 1;
-
-       while (p < end) {
-               /*
-                *      Replace the first \n by a comma, and remaining
-                *      ones by a space.
-                */
-               if (*p == '\n') {
-                       if (comma) {
-                               *(p++) = ' ';
-                       } else {
-                               *p = ',';
-                               last_comma = p;
-                               p++;
-                       }
-
-                       comma = 0;
-                       continue;
-               }
-
-               if (*p == ',') {
-                       comma++;
-                       last_comma = p;
-                       p++;
-                       continue;
-               }
-
-               last_comma = NULL;
-               p++;
-       }
-
-       /*
-        *      Don't end with a trailing comma
-        */
-       if (last_comma) *last_comma = '\0';
+       root = (fr_pair_parse_t) {
+               .ctx = ctx,
+               .da = fr_dict_root(dict),
+               .list = out,
+               .allow_crlf = true,
+       };
+       relative = (fr_pair_parse_t) { };
 
-       if (fr_pair_list_afrom_str(ctx, fr_dict_root(dict), box->vb_strvalue, box->vb_length, out) == T_INVALID) {
+       if (fr_pair_list_afrom_substr(&root, &relative, &FR_SBUFF_IN(box->vb_strvalue, box->vb_length)) < 0) {
                return;
        }
 
        /*
         *      Mark the attributes as tainted.
         */
-       fr_pair_list_tainted(out);
+       if (box->tainted) fr_pair_list_tainted(out);
 }
 
 static const char spaces[] = "                                                                                                                                ";
index 219c68f8134512dc7752bb6a3cf3fc8502d86b55..b0013143e5bd9fd269dbd9a6aca651813c23aa34 100644 (file)
@@ -57,6 +57,7 @@ static fr_sbuff_term_t const  bareword_terminals =
 
 static fr_table_num_sorted_t const pair_assignment_op_table[] = {
        { L("+="),      T_OP_ADD_EQ             },
+       { L(":="),      T_OP_EQ                 },
        { L("="),       T_OP_EQ                 },
 };
 static ssize_t pair_assignment_op_table_len = NUM_ELEMENTS(pair_assignment_op_table);
@@ -502,6 +503,13 @@ done:
 
        if (fr_sbuff_next_if_char(&our_in, ',')) goto redo;
 
+       if (relative->allow_crlf) {
+               size_t len;
+
+               len = fr_sbuff_adv_past_allowed(&our_in, SIZE_MAX, sbuff_char_line_endings, NULL);
+               if (len > 0) goto redo;
+       }
+
        FR_SBUFF_SET_RETURN(in, &our_in);
 }
 
index 90a23c7417b2d3655aefe08c00b951420b86c0ea..ddebb8ce94b0be004fce8e457945c527b0bf3b19 100644 (file)
@@ -46,6 +46,7 @@ typedef struct fr_pair_parse_s {
        fr_dict_attr_t const    *da;
        fr_pair_list_t          *list;
        bool                    allow_compare;
+       bool                    allow_crlf;
 } fr_pair_parse_t;
 
 fr_slen_t fr_pair_list_afrom_substr(fr_pair_parse_t const *root, fr_pair_parse_t *relative,