From: Alan T. DeKok Date: Tue, 1 Apr 2025 01:11:06 +0000 (-0400) Subject: remove unused functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6972172d8b03e22db4353bceab9bac0d7b872315;p=thirdparty%2Ffreeradius-server.git remove unused functions in the interest of removing 'tainted', remove functions which use 'tainted', but which aren't used anywhere. --- diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index 8f44f4e02a1..836644a1760 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -2870,53 +2870,6 @@ int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool ta return ret; } -/** Append bytes from a buffer to an existing "string" type value pair - * - * @param[in,out] vp to update. - * @param[in] src data to copy. - * @param[in] len of data to copy. - * @param[in] tainted Whether the value came from a trusted source. - * @return - * - 0 on success. - * - -1 on failure. - */ -int fr_pair_value_bstrn_append(fr_pair_t *vp, char const *src, size_t len, bool tainted) -{ - int ret; - - if (!fr_cond_assert(vp->vp_type == FR_TYPE_STRING)) return -1; - - ret = fr_value_box_bstrn_append(vp, &vp->data, src, len, tainted); - if (ret == 0) { - PAIR_VERIFY(vp); - } - - return ret; -} - -/** Append a talloced buffer to an existing "string" type value pair - * - * @param[in,out] vp to update. - * @param[in] src a talloced nul terminated buffer. - * @param[in] tainted Whether the value came from a trusted source. - * @return - * - 0 on success. - * - -1 on failure. - */ -int fr_pair_value_bstr_append_buffer(fr_pair_t *vp, char const *src, bool tainted) -{ - int ret; - - if (!fr_cond_assert(vp->vp_type == FR_TYPE_STRING)) return -1; - - ret = fr_value_box_bstr_append_buffer(vp, &vp->data, src, tainted); - if (ret == 0) { - PAIR_VERIFY(vp); - } - - return ret; -} - /** Pre-allocate a memory buffer for a "octets" type value pair * * @note Will clear existing values (including buffers). @@ -3068,53 +3021,6 @@ int fr_pair_value_memdup_buffer_shallow(fr_pair_t *vp, uint8_t const *src, bool } -/** Append bytes from a buffer to an existing "octets" type value pair - * - * @param[in,out] vp to update. - * @param[in] src data to copy. - * @param[in] len of data to copy. - * @param[in] tainted Whether the value came from a trusted source. - * @return - * - 0 on success. - * - -1 on failure. - */ -int fr_pair_value_mem_append(fr_pair_t *vp, uint8_t *src, size_t len, bool tainted) -{ - int ret; - - if (!fr_cond_assert(vp->vp_type == FR_TYPE_OCTETS)) return -1; - - ret = fr_value_box_mem_append(vp, &vp->data, src, len, tainted); - if (ret == 0) { - PAIR_VERIFY(vp); - } - - return ret; -} - -/** Append a talloced buffer to an existing "octets" type value pair - * - * @param[in,out] vp to update. - * @param[in] src data to copy. - * @param[in] tainted Whether the value came from a trusted source. - * @return - * - 0 on success. - * - -1 on failure. - */ -int fr_pair_value_mem_append_buffer(fr_pair_t *vp, uint8_t *src, bool tainted) -{ - int ret; - - if (!fr_cond_assert(vp->vp_type == FR_TYPE_OCTETS)) return -1; - - ret = fr_value_box_mem_append_buffer(vp, &vp->data, src, tainted); - if (ret == 0) { - PAIR_VERIFY(vp); - } - - return ret; -} - /** Return a const buffer for an enum type attribute * * Where the vp type is numeric but does not have any enumv, or its value diff --git a/src/lib/util/pair.h b/src/lib/util/pair.h index a1aac7ea57d..4832395b5b4 100644 --- a/src/lib/util/pair.h +++ b/src/lib/util/pair.h @@ -791,9 +791,6 @@ int fr_pair_value_bstrndup_shallow(fr_pair_t *vp, char const *src, size_t len, int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull); -int fr_pair_value_bstrn_append(fr_pair_t *vp, char const *src, size_t len, bool tainted) CC_HINT(nonnull(1)); - -int fr_pair_value_bstr_append_buffer(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull); /** @} */ /** @name Assign and manipulate octets strings @@ -812,9 +809,6 @@ int fr_pair_value_memdup_shallow(fr_pair_t *vp, uint8_t const *src, size_t len, int fr_pair_value_memdup_buffer_shallow(fr_pair_t *vp, uint8_t const *src, bool tainted) CC_HINT(nonnull); -int fr_pair_value_mem_append(fr_pair_t *vp, uint8_t *src, size_t len, bool tainted) CC_HINT(nonnull(1)); - -int fr_pair_value_mem_append_buffer(fr_pair_t *vp, uint8_t *src, bool tainted) CC_HINT(nonnull); /** @} */ /** @name Enum functions diff --git a/src/lib/util/pair_tests.c b/src/lib/util/pair_tests.c index 24737157c80..3486edef1de 100644 --- a/src/lib/util/pair_tests.c +++ b/src/lib/util/pair_tests.c @@ -1104,69 +1104,6 @@ static void test_fr_pair_value_bstrdup_buffer_shallow(void) talloc_free(copy_test_string); } -static void test_fr_pair_value_bstrn_append(void) -{ - fr_pair_t *vp; - char *copy_test_string; - - TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, NULL, fr_dict_attr_test_string)) != NULL); - - TEST_CASE("Validating PAIR_VERIFY()"); - PAIR_VERIFY(vp); - - copy_test_string = talloc_strdup(vp, test_string); - talloc_set_type(copy_test_string, char); - - TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_bstrndup()"); - TEST_CHECK(fr_pair_value_bstrndup(vp, test_string, test_string_len, false) == 0); - - TEST_CASE("Append the 'copy_test_string' value using fr_pair_value_bstrn_append()"); - TEST_CHECK(fr_pair_value_bstrn_append(vp, copy_test_string, test_string_len, true) == 0); - - // awful hack, just verify the first part of buffer and then the second part. yep, just appended twice. - TEST_CASE("Check 1. part (vp->vp_string == test_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue, test_string, test_string_len) == 0); - - TEST_CASE("Check 2. part ((vp->vp_string+test_string_len) == test_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue+test_string_len, test_string, test_string_len) == 0); - - talloc_free(copy_test_string); -} - -static void test_fr_pair_value_bstr_append_buffer(void) -{ - fr_pair_t *vp; - char *copy_test_string; - - TEST_CASE("Find 'Test-String'"); - TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, NULL, fr_dict_attr_test_string)) != NULL); - - TEST_CASE("Validating PAIR_VERIFY()"); - PAIR_VERIFY(vp); - - copy_test_string = talloc_strdup(vp, test_string); - talloc_set_type(copy_test_string, char); - - TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_bstrndup()"); - TEST_CHECK(fr_pair_value_bstrndup(vp, test_string, test_string_len, false) == 0); - - TEST_CASE("Append the 'copy_test_string' value using fr_pair_value_bstr_append_buffer()"); - TEST_CHECK(fr_pair_value_bstr_append_buffer(vp, copy_test_string, true) == 0); - - TEST_CASE("Validating PAIR_VERIFY()"); - PAIR_VERIFY(vp); - - // awful hack, just verify the first part of buffer and then the second part. yep, just appended twice. - TEST_CASE("Check 1. part (vp->vp_string == test_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue, test_string, test_string_len) == 0); - - TEST_CASE("Check 2. part ((vp->vp_string+test_string_len) == test_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue+test_string_len, test_string, test_string_len) == 0); - - talloc_free(copy_test_string); -} - static void test_fr_pair_value_mem_alloc(void) { fr_pair_t *vp; @@ -1315,60 +1252,6 @@ static void test_fr_pair_value_memdup_buffer_shallow(void) talloc_free(copy_test_octets); } -static void test_fr_pair_value_mem_append(void) -{ - fr_pair_t *vp; - - TEST_CASE("Find 'Test-Octets'"); - TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, NULL, fr_dict_attr_test_octets)) != NULL); - - TEST_CASE("Validating PAIR_VERIFY()"); - PAIR_VERIFY(vp); - - TEST_CASE("Copy content of 'test_octets' to attribute value using fr_pair_value_memdup()"); - TEST_CHECK(fr_pair_value_memdup(vp, test_octets, NUM_ELEMENTS(test_octets), false) == 0); - - TEST_CASE("Append the 'test_octets' value using fr_pair_value_mem_append()"); - TEST_CHECK(fr_pair_value_mem_append(vp, test_octets, NUM_ELEMENTS(test_octets), true) == 0); - - // awful hack, just verify the first part of buffer and then the second part. yep, just appended twice. - TEST_CASE("Check 1. part (vp->vp_octets == test_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0); - - TEST_CASE("Check 2. part ((vp->vp_string+NUM_ELEMENTS(test_octets)) == test_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets+NUM_ELEMENTS(test_octets), test_octets, NUM_ELEMENTS(test_octets)) == 0); -} - -static void test_fr_pair_value_mem_append_buffer(void) -{ - fr_pair_t *vp; - uint8_t *copy_test_octets; - - TEST_CASE("Find 'Test-Octets'"); - TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, NULL, fr_dict_attr_test_octets)) != NULL); - - TEST_CASE("Validating PAIR_VERIFY()"); - PAIR_VERIFY(vp); - - copy_test_octets = talloc_memdup(vp, test_octets, NUM_ELEMENTS(test_octets)); - talloc_set_type(copy_test_octets, uint8_t); - - TEST_CASE("Copy content of 'copy_test_octets' to attribute value using fr_pair_value_memdup()"); - TEST_CHECK(fr_pair_value_memdup(vp, copy_test_octets, NUM_ELEMENTS(test_octets), false) == 0); - - TEST_CASE("Append the 'copy_test_octets' value using fr_pair_value_mem_append_buffer()"); - TEST_CHECK(fr_pair_value_mem_append_buffer(vp, copy_test_octets, true) == 0); - - // awful hack, just verify the first part of buffer and then the second part. yep, just appended twice. - TEST_CASE("Check 1. part (vp->vp_octets == test_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0); - - TEST_CASE("Check 2. part ((vp->vp_string+NUM_ELEMENTS(test_octets)) == test_octets)"); - TEST_CHECK(vp && memcmp(vp->vp_octets+NUM_ELEMENTS(test_octets), test_octets, NUM_ELEMENTS(test_octets)) == 0); - - talloc_free(copy_test_octets); -} - static void test_fr_pair_value_enum(void) { fr_pair_t *vp; @@ -1472,8 +1355,6 @@ TEST_LIST = { { "fr_pair_value_bstrdup_buffer", test_fr_pair_value_bstrdup_buffer }, { "fr_pair_value_bstrndup_shallow", test_fr_pair_value_bstrndup_shallow }, { "fr_pair_value_bstrdup_buffer_shallow", test_fr_pair_value_bstrdup_buffer_shallow }, - { "fr_pair_value_bstrn_append", test_fr_pair_value_bstrn_append }, - { "fr_pair_value_bstr_append_buffer", test_fr_pair_value_bstr_append_buffer }, /* Assign and manipulate octets strings */ { "fr_pair_value_mem_alloc", test_fr_pair_value_mem_alloc }, @@ -1482,9 +1363,7 @@ TEST_LIST = { { "fr_pair_value_memdup_buffer", test_fr_pair_value_memdup_buffer }, { "fr_pair_value_memdup_shallow", test_fr_pair_value_memdup_shallow }, { "fr_pair_value_memdup_buffer_shallow", test_fr_pair_value_memdup_buffer_shallow }, - { "fr_pair_value_mem_append", test_fr_pair_value_mem_append }, - { "fr_pair_value_mem_append_buffer", test_fr_pair_value_mem_append_buffer }, - + /* Enum functions */ { "fr_pair_value_enum", test_fr_pair_value_enum }, { "fr_pair_value_enum_box", test_fr_pair_value_enum_box }, diff --git a/src/lib/util/value.c b/src/lib/util/value.c index 2ed8c16cd14..dfa9b691c94 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -4300,85 +4300,6 @@ int fr_value_box_bstrdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr return 0; } -/** Append bytes from a buffer to an existing #fr_value_box_t - * - * @param[in] ctx Where to allocate any talloc buffers required. - * @param[in] dst value box to append to. - * @param[in] src octets data to append. - * @param[in] len length of octets data. - * @param[in] tainted Whether src is tainted. - * @return - * - 0 on success. - * - -1 on failure. - */ -int fr_value_box_bstrn_append(TALLOC_CTX *ctx, fr_value_box_t *dst, char const *src, size_t len, bool tainted) -{ - char *ptr, *nptr; - size_t nlen; - - if (len == 0) return 0; - - if (dst->type != FR_TYPE_STRING) { - fr_strerror_printf("%s: Expected boxed value of type %s, got type %s", __FUNCTION__, - fr_type_to_str(FR_TYPE_STRING), - fr_type_to_str(dst->type)); - return -1; - } - - ptr = dst->datum.ptr; - if (!fr_cond_assert(ptr)) return -1; - - if (talloc_reference_count(ptr) > 0) { - fr_strerror_printf("%s: Boxed value has too many references", __FUNCTION__); - return -1; - } - - nlen = dst->vb_length + len + 1; - nptr = talloc_realloc(ctx, ptr, char, dst->vb_length + len + 1); - if (!nptr) { - fr_strerror_printf("%s: Realloc of %s array from %zu to %zu bytes failed", - __FUNCTION__, talloc_get_name(ptr), talloc_array_length(ptr), nlen); - return -1; - } - talloc_set_type(nptr, char); - ptr = nptr; - - memcpy(ptr + dst->vb_length, src, len); /* Copy data into the realloced buffer */ - - dst->tainted = dst->tainted || tainted; - dst->datum.ptr = ptr; - dst->vb_length += len; - - ptr[dst->vb_length] = '\0'; - - return 0; -} - -/** Append a talloced buffer to an existing fr_value_box_t - * - * @param[in] ctx Where to allocate any talloc buffers required. - * @param[in] dst value box to append to. - * @param[in] src string data to append. - * @param[in] tainted Whether src is tainted. - * @return - * - 0 on success. - * - -1 on failure. - */ -int fr_value_box_bstr_append_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, char const *src, bool tainted) -{ - size_t len; - - (void) talloc_get_type_abort_const(src, char); - - len = talloc_array_length(src); - if ((len == 0) || (src[len - 1] != '\0')) { - fr_strerror_const("Input buffer not \\0 terminated"); - return -1; - } - - return fr_value_box_bstrn_append(ctx, dst, src, len - 1, tainted); -} - /** Pre-allocate an octets buffer for filling by the caller * * @note Buffer will not be zeroed, as it's assumed the caller will be filling it. @@ -4603,72 +4524,6 @@ void fr_value_box_memdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr dst->vb_length = talloc_array_length(src); } -/** Append data to an existing fr_value_box_t - * - * @param[in] ctx Where to allocate any talloc buffers required. - * @param[in] dst value box to append to. - * @param[in] src octets data to append. - * @param[in] len length of octets data. - * @param[in] tainted Whether src is tainted. - * @return - * - 0 on success. - * - -1 on failure. - */ -int fr_value_box_mem_append(TALLOC_CTX *ctx, fr_value_box_t *dst, uint8_t const *src, size_t len, bool tainted) -{ - uint8_t *nptr; - size_t nlen; - - if (len == 0) return 0; - - if (dst->type != FR_TYPE_OCTETS) { - fr_strerror_printf("%s: Expected boxed value of type %s, got type %s", __FUNCTION__, - fr_type_to_str(FR_TYPE_OCTETS), - fr_type_to_str(dst->type)); - return -1; - } - - if (!fr_cond_assert(dst->datum.ptr)) return -1; - - if (talloc_reference_count(dst->datum.ptr) > 0) { - fr_strerror_printf("%s: Boxed value has too many references", __FUNCTION__); - return -1; - } - - nlen = dst->vb_length + len; - nptr = talloc_realloc(ctx, dst->datum.ptr, uint8_t, dst->vb_length + len); - if (!nptr) { - fr_strerror_printf("%s: Realloc of %s array from %zu to %zu bytes failed", - __FUNCTION__, - talloc_get_name(dst->datum.ptr), - talloc_array_length((uint8_t const *)dst->datum.ptr), nlen); - return -1; - } - - memcpy(nptr + dst->vb_length, src, len); /* Copy data into the realloced buffer */ - - dst->tainted = dst->tainted || tainted; - dst->datum.ptr = nptr; - dst->vb_length += len; - - return 0; -} - -/** Append a talloc buffer to an existing fr_value_box_t - * - * @param[in] ctx Where to allocate any talloc buffers required. - * @param[in] dst value box to append to. - * @param[in] src octets data to append. - * @param[in] tainted Whether src is tainted. - * @return - * - 0 on success. - * - -1 on failure. - */ -int fr_value_box_mem_append_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, uint8_t const *src, bool tainted) -{ - return fr_value_box_mem_append(ctx, dst, src, talloc_array_length(src), tainted); -} - /** Increment a boxed value * * Implements safe integer overflow. diff --git a/src/lib/util/value.h b/src/lib/util/value.h index cf5b5d0119e..deb489f98c3 100644 --- a/src/lib/util/value.h +++ b/src/lib/util/value.h @@ -1155,11 +1155,6 @@ int fr_value_box_bstrdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, f char const *src, bool tainted) CC_HINT(nonnull(2,4)); -int fr_value_box_bstrn_append(TALLOC_CTX *ctx, fr_value_box_t *dst, char const *src, size_t len, bool tainted) - CC_HINT(nonnull(2,3)); - -int fr_value_box_bstr_append_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, char const *src, bool tainted) - CC_HINT(nonnull(2,3)); /** @} */ /** @name Assign and manipulate octets strings @@ -1193,12 +1188,6 @@ void fr_value_box_memdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, f uint8_t const *src, bool tainted) CC_HINT(nonnull(2,4)); -int fr_value_box_mem_append(TALLOC_CTX *ctx, fr_value_box_t *dst, - uint8_t const *src, size_t len, bool tainted) - CC_HINT(nonnull(2,3)); - -int fr_value_box_mem_append_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, uint8_t const *src, bool tainted) - CC_HINT(nonnull(2,3)); /** @} */ void fr_value_box_increment(fr_value_box_t *vb)