From: Arran Cudbard-Bell Date: Fri, 10 Jun 2022 23:58:29 +0000 (-0500) Subject: Fix garbage test that leads to bad pairs in the test pair list X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54bc1dbd536960feb9463ce47a2aaa57f193d79c;p=thirdparty%2Ffreeradius-server.git Fix garbage test that leads to bad pairs in the test pair list --- diff --git a/src/lib/util/pair_test_helpers.h b/src/lib/util/pair_test_helpers.h index 05b4db6223c..060cce4c31c 100644 --- a/src/lib/util/pair_test_helpers.h +++ b/src/lib/util/pair_test_helpers.h @@ -53,6 +53,8 @@ static inline int fr_pair_test_list_alloc(TALLOC_CTX *ctx, fr_pair_list_t *out, p->attr != -1; p++) if (fr_pair_prepend_by_da(ctx, NULL, out, *p->da) < 0) return -1; + PAIR_LIST_VERIFY(out); + return 0; } diff --git a/src/lib/util/pair_tests.c b/src/lib/util/pair_tests.c index 06940e0197d..8aedfb389aa 100644 --- a/src/lib/util/pair_tests.c +++ b/src/lib/util/pair_tests.c @@ -605,7 +605,7 @@ static void test_fr_pair_value_strdup(void) static void test_fr_pair_value_strdup_shallow(void) { - fr_pair_t *vp; + fr_pair_t *vp, *nvp; char *copy_test_string; TEST_CASE("Find 'Test-String'"); @@ -614,19 +614,21 @@ static void test_fr_pair_value_strdup_shallow(void) TEST_CASE("Validating PAIR_VERIFY()"); PAIR_VERIFY(vp); - copy_test_string = talloc_strdup(vp, test_string); + MEM(nvp = fr_pair_copy(NULL, vp)); + + copy_test_string = talloc_strdup(nvp, test_string); talloc_set_type(copy_test_string, char); TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_strdup_shallow()"); - TEST_CHECK(fr_pair_value_strdup_shallow(vp, copy_test_string, true) == 0); + TEST_CHECK(fr_pair_value_strdup_shallow(nvp, copy_test_string, true) == 0); TEST_CASE("Validating PAIR_VERIFY()"); - PAIR_VERIFY(vp); + PAIR_VERIFY(nvp); TEST_CASE("Check (vp->vp_string == copy_test_string)"); - TEST_CHECK(vp && strncmp(vp->vp_strvalue, test_string, strlen(copy_test_string)) == 0); + TEST_CHECK(nvp && strncmp(nvp->vp_strvalue, test_string, strlen(copy_test_string)) == 0); - talloc_free(copy_test_string); + talloc_free(nvp); } static void test_fr_pair_value_strtrim(void)