]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Just clear the value, don't trash the metadata
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 24 May 2020 20:03:16 +0000 (15:03 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 24 May 2020 20:03:16 +0000 (15:03 -0500)
src/lib/util/pair_legacy.c
src/lib/util/value.c
src/lib/util/value.h

index 41e2dd0d5f9fc164f5529f6b67697927e1aa2b44..fcf9128829014991138c992281a559b758fce837 100644 (file)
@@ -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;
 
index d8ceb3e5c8bcb545d7314c0832366cc9a4e343ed..5f158915ec5608830e52603f260cb80aea0f4451 100644 (file)
@@ -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
index 2a682708c099f87b64f28304965524f177b64503..6990f386e8664109c9826907d8d436da8ebe4cf1 100644 (file)
@@ -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
  */