From: Arran Cudbard-Bell Date: Sun, 11 Dec 2022 21:04:48 +0000 (-0600) Subject: Don't use the unsafe value box copy macro X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55a1d9dd4bd3b367e01a3c191b8bcd67b276ac29;p=thirdparty%2Ffreeradius-server.git Don't use the unsafe value box copy macro --- diff --git a/src/lib/redis/redis.c b/src/lib/redis/redis.c index d8d82cc28ed..888ef6b6efe 100644 --- a/src/lib/redis/redis.c +++ b/src/lib/redis/redis.c @@ -25,6 +25,7 @@ */ #include #include +#include fr_table_num_sorted_t const redis_reply_types[] = { { L("array"), REDIS_REPLY_ARRAY }, @@ -210,7 +211,7 @@ int fr_redis_reply_to_value_box(TALLOC_CTX *ctx, fr_value_box_t *out, redisReply fr_value_box_t *to_cast; if (dst_type != FR_TYPE_VOID) { - fr_value_box_copy_unsafe(&in, &(fr_value_box_t){}); + fr_value_box_init_null(&in); to_cast = ∈ } else { to_cast = out; diff --git a/src/lib/util/value.h b/src/lib/util/value.h index f24625dec2b..13150e485db 100644 --- a/src/lib/util/value.h +++ b/src/lib/util/value.h @@ -419,17 +419,6 @@ void fr_value_box_copy_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src) CC_HINT(nonnull(2,3)); -/* - * fr_value_box_copy_unsafe() copies the raw bytes from one value box - * to another. Its uses are rare. - */ -static inline CC_HINT(nonnull, always_inline) -void fr_value_box_copy_unsafe(fr_value_box_t *dst, const fr_value_box_t *src) -{ - /* coverity[store_writes_const_field] */ - memcpy(dst, src, sizeof(*dst)); -} - int fr_value_box_steal(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t *src) CC_HINT(nonnull(2,3)); /** @} */ @@ -454,11 +443,11 @@ int fr_value_box_steal(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t *sr static inline CC_HINT(nonnull(1), always_inline) void fr_value_box_init(fr_value_box_t *vb, fr_type_t type, fr_dict_attr_t const *enumv, bool tainted) { - fr_value_box_copy_unsafe(vb, &(fr_value_box_t){ - .type = type, - .enumv = enumv, - .tainted = tainted - }); + memcpy(vb, &(fr_value_box_t){ + .type = type, + .enumv = enumv, + .tainted = tainted + }, sizeof(*vb)); fr_value_box_list_entry_init(vb); /* diff --git a/src/modules/rlm_rest/rest.c b/src/modules/rlm_rest/rest.c index 982de5ef1d0..01608f6b10b 100644 --- a/src/modules/rlm_rest/rest.c +++ b/src/modules/rlm_rest/rest.c @@ -23,6 +23,7 @@ * @copyright 2012-2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org) */ + RCSID("$Id$") #define LOG_PREFIX mctx->inst->name @@ -34,6 +35,7 @@ RCSID("$Id$") #include #include #include +#include #include "rest.h" @@ -869,7 +871,7 @@ static fr_pair_t *json_pair_alloc_leaf(UNUSED rlm_rest_t const *instance, UNUSED return NULL; } - fr_value_box_copy_unsafe(&src, &(fr_value_box_t){}); + fr_value_box_init_null(&src); switch (json_object_get_type(leaf)) { case json_type_int: