From: Arran Cudbard-Bell Date: Sun, 24 May 2020 20:03:16 +0000 (-0500) Subject: Just clear the value, don't trash the metadata X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3aec3facf77cb3a5abe57a84bea79b06665902b2;p=thirdparty%2Ffreeradius-server.git Just clear the value, don't trash the metadata --- diff --git a/src/lib/util/pair_legacy.c b/src/lib/util/pair_legacy.c index 41e2dd0d5f9..fcf91288290 100644 --- a/src/lib/util/pair_legacy.c +++ b/src/lib/util/pair_legacy.c @@ -295,7 +295,7 @@ VALUE_PAIR *fr_pair_make(TALLOC_CTX *ctx, fr_dict_t const *dict, VALUE_PAIR **vp switch (vp->op) { case T_OP_CMP_TRUE: case T_OP_CMP_FALSE: - fr_value_box_clear(&vp->data); + fr_value_box_clear_value(&vp->data); value = NULL; /* ignore it! */ break; diff --git a/src/lib/util/value.c b/src/lib/util/value.c index d8ceb3e5c8b..5f158915ec5 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -288,7 +288,7 @@ size_t const fr_value_box_offsets[] = { [FR_TYPE_MAX] = 0 //!< Ensure array covers all types. }; -/** Clear/free any existing value +/** Clear/free any existing value and metadata * * @note Do not use on uninitialised memory. * @@ -299,8 +299,7 @@ inline void fr_value_box_clear(fr_value_box_t *data) switch (data->type) { case FR_TYPE_OCTETS: case FR_TYPE_STRING: - TALLOC_FREE(data->datum.ptr); - data->datum.length = 0; + talloc_free(data->datum.ptr); break; case FR_TYPE_STRUCTURAL: @@ -317,6 +316,34 @@ inline void fr_value_box_clear(fr_value_box_t *data) fr_value_box_init(data, FR_TYPE_INVALID, NULL, false); } +/** Clear/free any existing value + * + * @note Do not use on uninitialised memory. + * + * @param[in] data to clear. + */ +inline void fr_value_box_clear_value(fr_value_box_t *data) +{ + switch (data->type) { + case FR_TYPE_OCTETS: + case FR_TYPE_STRING: + talloc_free(data->datum.ptr); + break; + + case FR_TYPE_STRUCTURAL: + fr_assert_fail(NULL); + return; + + case FR_TYPE_INVALID: + return; + + default: + break; + } + + memset(&data->datum, 0, sizeof(data->datum)); +} + /** Copy flags and type data from one value box to another * * @param[in] dst to copy flags to diff --git a/src/lib/util/value.h b/src/lib/util/value.h index 2a682708c09..6990f386e86 100644 --- a/src/lib/util/value.h +++ b/src/lib/util/value.h @@ -538,6 +538,8 @@ _Generic((_var), \ */ void fr_value_box_clear(fr_value_box_t *data); +void fr_value_box_clear_value(fr_value_box_t *data); + /* * Comparison */