From: Arran Cudbard-Bell Date: Wed, 14 Dec 2022 23:46:29 +0000 (-0600) Subject: Move vb size field into a struct with the ptr types in fr_value_box_t X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77cf03cc9dbf45141df4d75f17a537b4b96bdaff;p=thirdparty%2Ffreeradius-server.git Move vb size field into a struct with the ptr types in fr_value_box_t Print some extra size information in radsize --- diff --git a/src/lib/ldap/filter.c b/src/lib/ldap/filter.c index 57e50236f39..c22f401ad06 100644 --- a/src/lib/ldap/filter.c +++ b/src/lib/ldap/filter.c @@ -445,7 +445,7 @@ static bool ldap_filter_node_eval(ldap_filter_t *node, fr_ldap_connection_t *con case LDAP_FILTER_OP_EQ: for (i = 0; i < count; i++) { DEBUG_LDAP_ATTR_VAL - if ((node->value->length == values[i]->bv_len) && + if ((node->value->vb_length == values[i]->bv_len) && (strncasecmp(values[i]->bv_val, node->value->vb_strvalue, values[i]->bv_len) == 0)) { filter_state = true; break; @@ -466,7 +466,7 @@ static bool ldap_filter_node_eval(ldap_filter_t *node, fr_ldap_connection_t *con * Point t_end at the final character of the filter value * - not the NULL - so we can check for trailing '*' */ - t_end = node->value->vb_strvalue + node->value->length - 1; + t_end = node->value->vb_strvalue + node->value->vb_length - 1; for (i = 0; i < count; i++) { DEBUG_LDAP_ATTR_VAL diff --git a/src/lib/server/map_async.c b/src/lib/server/map_async.c index 8ed1ef6842d..fdb905e65e9 100644 --- a/src/lib/server/map_async.c +++ b/src/lib/server/map_async.c @@ -158,13 +158,7 @@ static inline vp_list_mod_t *list_mod_empty_string_afrom_map(TALLOC_CTX *ctx, { vp_list_mod_t *n; map_t *mod; - fr_value_box_t empty_string = { - .type = FR_TYPE_STRING, - .datum = { - .strvalue = "", - }, - .length = 0, - }; + fr_value_box_t empty_string = *fr_box_strvalue_len("", 0); n = list_mod_alloc(ctx); if (!n) return NULL; diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index b1c820de45a..f7b783e6734 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -286,7 +286,7 @@ static int apply_edits_to_list(request_t *request, unlang_frame_state_edit_t *st * parent VP. Because we're going to be moving them to the parent VP at some * point. The ones which aren't moved will get deleted in this function. */ - token = fr_pair_list_afrom_str(state, da, box->vb_strvalue, box->length, children); + token = fr_pair_list_afrom_str(state, da, box->vb_strvalue, box->vb_length, children); if (token == T_INVALID) { RPEDEBUG("Failed parsing string '%pV' as attribute list", box); return -1; diff --git a/src/lib/util/calc.c b/src/lib/util/calc.c index 63badf72533..2d13341677e 100644 --- a/src/lib/util/calc.c +++ b/src/lib/util/calc.c @@ -845,7 +845,7 @@ static int calc_octets(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons COERCE_B(FR_TYPE_OCTETS, dst->enumv); } - len = a->length + b->length; + len = a->vb_length + b->vb_length; switch (op) { case T_ADD: /* dst = a . b */ @@ -985,7 +985,7 @@ static int calc_string(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons COERCE_B(FR_TYPE_STRING, dst->enumv); } - len = a->length + b->length; + len = a->vb_length + b->vb_length; switch (op) { case T_ADD: diff --git a/src/lib/util/uri.c b/src/lib/util/uri.c index 3a711586fbf..2e4fabb58b5 100644 --- a/src/lib/util/uri.c +++ b/src/lib/util/uri.c @@ -81,12 +81,12 @@ int fr_uri_escape(FR_DLIST_HEAD(fr_value_box_list) *uri, fr_uri_part_t const *ur /* * Zero length box - no terminators here */ - if (uri_vb->length == 0) continue; + if (uri_vb->vb_length == 0) continue; /* * Look for URI part terminator */ - fr_sbuff_init_in(&sbuff, uri_vb->vb_strvalue, uri_vb->length); + fr_sbuff_init_in(&sbuff, uri_vb->vb_strvalue, uri_vb->vb_length); do { fr_sbuff_adv_until(&sbuff, SIZE_MAX, uri_part->terminals, '\0'); diff --git a/src/listen/ldap_sync/proto_ldap_sync.c b/src/listen/ldap_sync/proto_ldap_sync.c index da71041596b..2d456057f48 100644 --- a/src/listen/ldap_sync/proto_ldap_sync.c +++ b/src/listen/ldap_sync/proto_ldap_sync.c @@ -222,7 +222,7 @@ static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8 if ((request->rcode != RLM_MODULE_OK) && (request->rcode != RLM_MODULE_UPDATED)) goto send; vp = fr_pair_find_by_da_nested(&request->reply_pairs, NULL, attr_ldap_sync_cookie); - if ((vp) && (vp->data.length > 0)) { + if ((vp) && (vp->data.vb_length > 0)) { fr_pair_remove(&request->reply_pairs, vp); fr_pair_steal_append(local, &pairs, vp); } diff --git a/src/modules/rlm_escape/rlm_escape.c b/src/modules/rlm_escape/rlm_escape.c index 829ccb89a79..e1919531f6b 100644 --- a/src/modules/rlm_escape/rlm_escape.c +++ b/src/modules/rlm_escape/rlm_escape.c @@ -78,7 +78,7 @@ static xlat_action_t escape_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, * as a starting point. The maximum length would be 12 * times the original if every character is 4 byte UTF8. */ - if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, arg->length * 2, arg->length * 12)) { + if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, arg->vb_length * 2, arg->vb_length * 12)) { error: RPEDEBUG("Failed to allocated buffer for escaped string"); talloc_free(vb); @@ -139,15 +139,15 @@ static xlat_action_t unescape_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, fr_value_box_t *vb; MEM(vb = fr_value_box_alloc_null(ctx)); - if (fr_value_box_bstr_alloc(ctx, &out_p, vb, NULL, arg->length, arg->tainted) < 0) { + if (fr_value_box_bstr_alloc(ctx, &out_p, vb, NULL, arg->vb_length, arg->tainted) < 0) { talloc_free(vb); RPEDEBUG("Failed allocating space for unescaped string"); return XLAT_ACTION_FAIL; } - sbuff = FR_SBUFF_IN(out_p, arg->length); + sbuff = FR_SBUFF_IN(out_p, arg->vb_length); p = arg->vb_strvalue; - end = p + arg->length; + end = p + arg->vb_length; while (*p) { if (*p != '=') { next: diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index 73db03f10f4..99544db14a9 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -197,7 +197,7 @@ static xlat_action_t ldap_escape_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, * Maximum space needed for output would be 3 times the input if every * char needed escaping */ - if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, in_vb->length * 3, in_vb->length * 3)) { + if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, in_vb->vb_length * 3, in_vb->vb_length * 3)) { REDEBUG("Failed to allocate buffer for escaped string"); talloc_free(vb); return XLAT_ACTION_FAIL; @@ -206,7 +206,7 @@ static xlat_action_t ldap_escape_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, /* * Call the escape function, including the space for the trailing NULL */ - len = fr_ldap_escape_func(request, fr_sbuff_buff(&sbuff), in_vb->length * 3 + 1, in_vb->vb_strvalue, NULL); + len = fr_ldap_escape_func(request, fr_sbuff_buff(&sbuff), in_vb->vb_length * 3 + 1, in_vb->vb_strvalue, NULL); /* * Trim buffer to fit used space and assign to box @@ -234,7 +234,7 @@ static xlat_action_t ldap_unescape_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, /* * Maximum space needed for output will be the same as the input */ - if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, in_vb->length, in_vb->length)) { + if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, in_vb->vb_length, in_vb->vb_length)) { REDEBUG("Failed to allocate buffer for unescaped string"); talloc_free(vb); return XLAT_ACTION_FAIL; @@ -243,7 +243,7 @@ static xlat_action_t ldap_unescape_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, /* * Call the unescape function, including the space for the trailing NULL */ - len = fr_ldap_unescape_func(request, fr_sbuff_buff(&sbuff), in_vb->length + 1, in_vb->vb_strvalue, NULL); + len = fr_ldap_unescape_func(request, fr_sbuff_buff(&sbuff), in_vb->vb_length + 1, in_vb->vb_strvalue, NULL); /* * Trim buffer to fit used space and assign to box @@ -268,7 +268,7 @@ static int uri_part_escape(fr_value_box_t *vb, UNUSED void *uctx) * Maximum space needed for output would be 3 times the input if every * char needed escaping */ - if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, vb->length * 3, vb->length * 3)) { + if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, vb->vb_length * 3, vb->vb_length * 3)) { fr_strerror_printf_push("Failed to allocate buffer for escaped argument"); return -1; } @@ -276,7 +276,7 @@ static int uri_part_escape(fr_value_box_t *vb, UNUSED void *uctx) /* * Call the escape function, including the space for the trailing NULL */ - len = fr_ldap_escape_func(NULL, fr_sbuff_buff(&sbuff), vb->length * 3 + 1, vb->vb_strvalue, NULL); + len = fr_ldap_escape_func(NULL, fr_sbuff_buff(&sbuff), vb->vb_length * 3 + 1, vb->vb_strvalue, NULL); fr_sbuff_trim_talloc(&sbuff, len); fr_value_box_clear_value(vb); diff --git a/src/modules/rlm_mschap/rlm_mschap.c b/src/modules/rlm_mschap/rlm_mschap.c index 3b0e8c86e7f..3ffee6df276 100644 --- a/src/modules/rlm_mschap/rlm_mschap.c +++ b/src/modules/rlm_mschap/rlm_mschap.c @@ -647,7 +647,7 @@ static xlat_action_t mschap_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, */ } else if (strncasecmp(arg->vb_strvalue, "NT-Hash", 7) == 0) { arg = fr_value_box_list_next(in, arg); - if ((!arg) || (arg->length == 0)) + if ((!arg) || (arg->vb_length == 0)) return XLAT_ACTION_FAIL; if (mschap_nt_password_hash(buffer, arg->vb_strvalue) < 0) { @@ -667,7 +667,7 @@ static xlat_action_t mschap_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, */ } else if (strncasecmp(arg->vb_strvalue, "LM-Hash", 7) == 0) { arg = fr_value_box_list_next(in, arg); - if ((!arg) || (arg->length == 0)) + if ((!arg) || (arg->vb_length == 0)) return XLAT_ACTION_FAIL; smbdes_lmpwdhash(arg->vb_strvalue, buffer); diff --git a/src/modules/rlm_perl/rlm_perl.c b/src/modules/rlm_perl/rlm_perl.c index dacd79eaea6..9ecd71e5e6c 100644 --- a/src/modules/rlm_perl/rlm_perl.c +++ b/src/modules/rlm_perl/rlm_perl.c @@ -285,7 +285,7 @@ static int perl_vblist_to_av(AV *av, FR_DLIST_HEAD(fr_value_box_list) *head) { while ((vb = fr_value_box_list_next(head, vb))) { switch (vb->type) { case FR_TYPE_STRING: - sv = newSVpvn(vb->vb_strvalue, vb->length); + sv = newSVpvn(vb->vb_strvalue, vb->vb_length); break; case FR_TYPE_OCTETS: @@ -484,9 +484,9 @@ static xlat_action_t perl_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, /* * Single child value - add as scalar */ - if (child->length == 0) continue; + if (child->vb_length == 0) continue; DEBUG3("Passing single value %pV", child); - sv = newSVpvn(child->vb_strvalue, child->length); + sv = newSVpvn(child->vb_strvalue, child->vb_length); if (child->tainted) SvTAINT(sv); XPUSHs(sv_2mortal(sv)); continue; diff --git a/src/modules/rlm_rest/rlm_rest.c b/src/modules/rlm_rest/rlm_rest.c index dba52c97e60..dba74b23aac 100644 --- a/src/modules/rlm_rest/rlm_rest.c +++ b/src/modules/rlm_rest/rlm_rest.c @@ -343,13 +343,13 @@ static int uri_part_escape(fr_value_box_t *vb, void *uctx) fr_curl_io_request_t *randle = talloc_get_type_abort(uctx, fr_curl_io_request_t); request_t *request = randle->request; - escaped = curl_easy_escape(randle->candle, vb->vb_strvalue, vb->length); + escaped = curl_easy_escape(randle->candle, vb->vb_strvalue, vb->vb_length); if (!escaped) return -1; /* * Returned string the same length - nothing changed */ - if (strlen(escaped) == vb->length) { + if (strlen(escaped) == vb->vb_length) { RDEBUG4("Tainted value %pV needed no escaping", vb); curl_free(escaped); return 0; diff --git a/src/modules/rlm_sql/rlm_sql.c b/src/modules/rlm_sql/rlm_sql.c index 58b37176c3c..b6f62d91fa5 100644 --- a/src/modules/rlm_sql/rlm_sql.c +++ b/src/modules/rlm_sql/rlm_sql.c @@ -178,12 +178,12 @@ static int sql_xlat_escape(request_t *request, fr_value_box_t *vb, void *uctx) /* * Maximum escaped length is 3 * original - if every character needs escaping */ - if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, vb->length * 3, vb->length * 3)) { + if (!fr_sbuff_init_talloc(vb, &sbuff, &sbuff_ctx, vb->vb_length * 3, vb->vb_length * 3)) { fr_strerror_printf_push("Failed to allocate buffer for escaped sql argument"); return -1; } - len = inst->sql_escape_func(request, fr_sbuff_buff(&sbuff), vb->length * 3 + 1, vb->vb_strvalue, handle); + len = inst->sql_escape_func(request, fr_sbuff_buff(&sbuff), vb->vb_length * 3 + 1, vb->vb_strvalue, handle); /* * fr_value_box_strdup_shallow resets the dlist entries - take a copy diff --git a/src/modules/rlm_unbound/rlm_unbound.c b/src/modules/rlm_unbound/rlm_unbound.c index 77b8a42e6d6..d09309f898a 100644 --- a/src/modules/rlm_unbound/rlm_unbound.c +++ b/src/modules/rlm_unbound/rlm_unbound.c @@ -351,7 +351,7 @@ static xlat_action_t xlat_unbound(TALLOC_CTX *ctx, fr_dcursor_t *out, fr_value_box_t *count_vb = fr_value_box_list_next(in, query_vb); unbound_request_t *ur; - if (host_vb->length == 0) { + if (host_vb->vb_length == 0) { REDEBUG("Can't resolve zero length host"); return XLAT_ACTION_FAIL; } diff --git a/src/modules/rlm_unpack/rlm_unpack.c b/src/modules/rlm_unpack/rlm_unpack.c index bdea90fe8eb..8e8879f4f04 100644 --- a/src/modules/rlm_unpack/rlm_unpack.c +++ b/src/modules/rlm_unpack/rlm_unpack.c @@ -88,10 +88,10 @@ static xlat_action_t unpack_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, } } else if (data_vb->type == FR_TYPE_STRING) { input = (uint8_t const *)data_vb->vb_strvalue; - input_len = data_vb->length; + input_len = data_vb->vb_length; } else { input = data_vb->vb_octets; - input_len = data_vb->length; + input_len = data_vb->vb_length; } offset = offset_vb->vb_uint32;