From: Alan T. DeKok Date: Sun, 29 Oct 2023 13:46:04 +0000 (-0400) Subject: remove more fr_pair_list_afrom_str() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=005b3d11a9e7f4d0c195121bc81040175ba4ffd0;p=thirdparty%2Ffreeradius-server.git remove more fr_pair_list_afrom_str() --- diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index 1b2a54462a3..9f293600787 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -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[] = " "; diff --git a/src/lib/util/pair_legacy.c b/src/lib/util/pair_legacy.c index 219c68f8134..b0013143e5b 100644 --- a/src/lib/util/pair_legacy.c +++ b/src/lib/util/pair_legacy.c @@ -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); } diff --git a/src/lib/util/pair_legacy.h b/src/lib/util/pair_legacy.h index 90a23c7417b..ddebb8ce94b 100644 --- a/src/lib/util/pair_legacy.h +++ b/src/lib/util/pair_legacy.h @@ -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,