]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix garbage test that leads to bad pairs in the test pair list
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 10 Jun 2022 23:58:29 +0000 (18:58 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 12 Jun 2022 01:07:53 +0000 (20:07 -0500)
src/lib/util/pair_test_helpers.h
src/lib/util/pair_tests.c

index 05b4db6223c2015fe3514dcd94c7a7449380c853..060cce4c31c0377ca7ec38dbff7231f613566feb 100644 (file)
@@ -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;
 }
 
index 06940e0197d9f22c05e609e6b8aff483558ecea8..8aedfb389aa8b1182ecc93cddf27db6e6f6f844f 100644 (file)
@@ -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)