From: Alan T. DeKok Date: Sat, 11 Dec 2021 00:09:29 +0000 (-0500) Subject: don't manually set VT_DATA everywhere X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=107a04377efef9db08bd240e0ca2570572de5f10;p=thirdparty%2Ffreeradius-server.git don't manually set VT_DATA everywhere it should be the default, unless we add a new API to allow fr_pair_t to contain fr_value_box_list_t --- diff --git a/src/lib/eap_aka_sim/decode.c b/src/lib/eap_aka_sim/decode.c index a05c0cfb2aa..e8cb3acf174 100644 --- a/src/lib/eap_aka_sim/decode.c +++ b/src/lib/eap_aka_sim/decode.c @@ -823,7 +823,6 @@ static ssize_t sim_decode_pair_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_di } done: - vp->type = VT_DATA; fr_pair_append(out, vp); return attr_len; diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index 7691bae4319..5ca5ea3e0da 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -113,7 +113,7 @@ static inline CC_HINT(always_inline) void pair_init_null(fr_pair_t *vp) * Legacy cruft */ vp->op = T_OP_EQ; - vp->type = VT_NONE; + vp->type = VT_DATA; } /** Dynamically allocate a new attribute with no #fr_dict_attr_t assigned @@ -1937,7 +1937,6 @@ int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, value, inlen, uerules, tainted) < 0) return -1; - vp->type = VT_DATA; PAIR_VERIFY(vp); @@ -1964,7 +1963,6 @@ int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted) fr_value_box_clear(&vp->data); /* Free any existing buffers */ ret = fr_value_box_strdup(vp, &vp->data, vp->da, src, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -1987,7 +1985,6 @@ int fr_pair_value_strdup_shallow(fr_pair_t *vp, char const *src, bool tainted) fr_value_box_clear(&vp->data); fr_value_box_strdup_shallow(&vp->data, vp->da, src, tainted); - vp->type = VT_DATA; PAIR_VERIFY(vp); return 0; @@ -2008,7 +2005,6 @@ int fr_pair_value_strtrim(fr_pair_t *vp) ret = fr_value_box_strtrim(vp, &vp->data); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2035,12 +2031,10 @@ int fr_pair_value_aprintf(fr_pair_t *vp, char const *fmt, ...) va_end(ap); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); - return 0; } - return -1; + return ret; } /** Pre-allocate a memory buffer for a "string" type value pair @@ -2065,7 +2059,6 @@ int fr_pair_value_bstr_alloc(fr_pair_t *vp, char **out, size_t size, bool tainte fr_value_box_clear(&vp->data); /* Free any existing buffers */ ret = fr_value_box_bstr_alloc(vp, out, &vp->data, vp->da, size, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2090,7 +2083,6 @@ int fr_pair_value_bstr_realloc(fr_pair_t *vp, char **out, size_t size) ret = fr_value_box_bstr_realloc(vp, out, &vp->data, size); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2121,7 +2113,6 @@ int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tain fr_value_box_clear(&vp->data); ret = fr_value_box_bstrndup(vp, &vp->data, vp->da, src, len, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2148,7 +2139,6 @@ int fr_pair_value_bstrdup_buffer(fr_pair_t *vp, char const *src, bool tainted) fr_value_box_clear(&vp->data); ret = fr_value_box_bstrdup_buffer(vp, &vp->data, vp->da, src, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2171,7 +2161,6 @@ int fr_pair_value_bstrndup_shallow(fr_pair_t *vp, char const *src, size_t len, b fr_value_box_clear(&vp->data); fr_value_box_bstrndup_shallow(&vp->data, vp->da, src, len, tainted); - vp->type = VT_DATA; PAIR_VERIFY(vp); return 0; @@ -2195,7 +2184,6 @@ int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool ta fr_value_box_clear(&vp->data); ret = fr_value_box_bstrdup_buffer_shallow(NULL, &vp->data, vp->da, src, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2220,7 +2208,6 @@ int fr_pair_value_bstrn_append(fr_pair_t *vp, char const *src, size_t len, bool ret = fr_value_box_bstrn_append(vp, &vp->data, src, len, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2244,7 +2231,6 @@ int fr_pair_value_bstr_append_buffer(fr_pair_t *vp, char const *src, bool tainte ret = fr_value_box_bstr_append_buffer(vp, &vp->data, src, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2273,7 +2259,6 @@ int fr_pair_value_mem_alloc(fr_pair_t *vp, uint8_t **out, size_t size, bool tain fr_value_box_clear(&vp->data); /* Free any existing buffers */ ret = fr_value_box_mem_alloc(vp, out, &vp->data, vp->da, size, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2298,7 +2283,6 @@ int fr_pair_value_mem_realloc(fr_pair_t *vp, uint8_t **out, size_t size) ret = fr_value_box_mem_realloc(vp, out, &vp->data, size); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2326,7 +2310,6 @@ int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t size, bool ta fr_value_box_clear(&vp->data); /* Free any existing buffers */ ret = fr_value_box_memdup(vp, &vp->data, vp->da, src, size, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2353,7 +2336,6 @@ int fr_pair_value_memdup_buffer(fr_pair_t *vp, uint8_t const *src, bool tainted) fr_value_box_clear(&vp->data); /* Free any existing buffers */ ret = fr_value_box_memdup_buffer(vp, &vp->data, vp->da, src, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2376,7 +2358,6 @@ int fr_pair_value_memdup_shallow(fr_pair_t *vp, uint8_t const *src, size_t len, fr_value_box_clear(&vp->data); fr_value_box_memdup_shallow(&vp->data, vp->da, src, len, tainted); - vp->type = VT_DATA; PAIR_VERIFY(vp); return 0; @@ -2397,7 +2378,6 @@ int fr_pair_value_memdup_buffer_shallow(fr_pair_t *vp, uint8_t const *src, bool fr_value_box_clear(&vp->data); fr_value_box_memdup_buffer_shallow(NULL, &vp->data, vp->da, src, tainted); - vp->type = VT_DATA; PAIR_VERIFY(vp); return 0; @@ -2422,7 +2402,6 @@ int fr_pair_value_mem_append(fr_pair_t *vp, uint8_t *src, size_t len, bool taint ret = fr_value_box_mem_append(vp, &vp->data, src, len, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } @@ -2446,7 +2425,6 @@ int fr_pair_value_mem_append_buffer(fr_pair_t *vp, uint8_t *src, bool tainted) ret = fr_value_box_mem_append_buffer(vp, &vp->data, src, tainted); if (ret == 0) { - vp->type = VT_DATA; PAIR_VERIFY(vp); } diff --git a/src/lib/util/pair.h b/src/lib/util/pair.h index f2894ab85d9..763eb86663d 100644 --- a/src/lib/util/pair.h +++ b/src/lib/util/pair.h @@ -51,9 +51,8 @@ extern "C" { * xlat is another type of data node which must first be expanded before use. */ typedef enum value_type { - VT_NONE = 0, //!< fr_pair_t has no value. - VT_SET, //!< fr_pair_t has children. - VT_LIST, //!< fr_pair_t has multiple values. + VT_INVALID = 0, //!< fr_pair_t is broken + VT_SET, //!< fr_pair_t is #fr_value_box_list VT_DATA, //!< fr_pair_t has a single value. } value_type_t; diff --git a/src/lib/util/struct.c b/src/lib/util/struct.c index 9ff0aa9a289..621a49a5518 100644 --- a/src/lib/util/struct.c +++ b/src/lib/util/struct.c @@ -53,7 +53,6 @@ fr_pair_t *fr_raw_from_network(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, ui return NULL; } - vp->type = VT_DATA; return vp; } @@ -200,7 +199,6 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, goto unknown; } - vp->type = VT_DATA; vp->vp_tainted = true; fr_pair_append(child_list, vp); p += (num_bits >> 3); /* go to the LAST bit, not the byte AFTER the last bit */ @@ -318,7 +316,6 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, return data_len; } - vp->type = VT_DATA; vp->vp_tainted = true; fr_pair_append(child_list, vp); diff --git a/src/listen/detail/proto_detail.c b/src/listen/detail/proto_detail.c index 2e994c31ff5..9d617087c5a 100644 --- a/src/listen/detail/proto_detail.c +++ b/src/listen/detail/proto_detail.c @@ -276,7 +276,6 @@ static int mod_decode(void const *instance, request_t *request, uint8_t *const d vp = fr_pair_afrom_da(request->request_ctx, attr_packet_original_timestamp); if (vp) { vp->vp_date = fr_unix_time_from_sec(timestamp); - vp->type = VT_DATA; fr_dcursor_append(&cursor, vp); } goto next; diff --git a/src/protocols/dhcpv6/base.c b/src/protocols/dhcpv6/base.c index 1f00ef2e83a..1700d4d0dd2 100644 --- a/src/protocols/dhcpv6/base.c +++ b/src/protocols/dhcpv6/base.c @@ -662,7 +662,6 @@ ssize_t fr_dhcpv6_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *pa if (!vp) return -1; vp->vp_uint32 = packet[0]; - vp->type = VT_DATA; fr_pair_append(&tmp, vp); switch (packet[0]) { @@ -723,7 +722,6 @@ ssize_t fr_dhcpv6_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *pa */ (void) fr_pair_value_memdup(vp, packet + 1, 3, false); - vp->type = VT_DATA; fr_pair_append(&tmp, vp); p = packet + 4; diff --git a/src/protocols/dhcpv6/decode.c b/src/protocols/dhcpv6/decode.c index 4dd2fa297e6..a82c937056b 100644 --- a/src/protocols/dhcpv6/decode.c +++ b/src/protocols/dhcpv6/decode.c @@ -91,7 +91,6 @@ static ssize_t decode_raw(TALLOC_CTX *ctx, fr_pair_list_t *out, UNUSED fr_dict_t return slen; } - vp->type = VT_DATA; vp->vp_tainted = true; fr_pair_append(out, vp); return data_len; @@ -266,7 +265,6 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t cons break; } - vp->type = VT_DATA; vp->vp_tainted = true; fr_pair_append(out, vp); return data_len; @@ -410,7 +408,6 @@ static ssize_t decode_dns_labels(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t goto raw; } - vp->type = VT_DATA; fr_pair_append(out, vp); } diff --git a/src/protocols/dns/decode.c b/src/protocols/dns/decode.c index 6dd5d378fd6..4edbe465007 100644 --- a/src/protocols/dns/decode.c +++ b/src/protocols/dns/decode.c @@ -73,7 +73,6 @@ static ssize_t decode_raw(TALLOC_CTX *ctx, fr_pair_list_t *out, UNUSED fr_dict_t return slen; } - vp->type = VT_DATA; vp->vp_tainted = true; fr_pair_append(out, vp); return data_len; @@ -223,7 +222,6 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t cons break; } - vp->type = VT_DATA; vp->vp_tainted = true; fr_pair_append(out, vp); return data_len; @@ -375,7 +373,6 @@ static ssize_t decode_dns_labels(TALLOC_CTX *ctx, fr_pair_list_t *out,UNUSED fr_ return -1; } - vp->type = VT_DATA; fr_pair_append(out, vp); } diff --git a/src/protocols/radius/decode.c b/src/protocols/radius/decode.c index f0ce23dd637..c9b8316cdd0 100644 --- a/src/protocols/radius/decode.c +++ b/src/protocols/radius/decode.c @@ -1706,7 +1706,6 @@ ssize_t fr_radius_decode_pair_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dic } done: - vp->type = VT_DATA; vp->vp_tainted = true; if (!tag) {