Skip to content

Commit 17a2abc

Browse files
committed
clean up more aggressively on error
1 parent ede4ad6 commit 17a2abc

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/lib/util/pair.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,12 @@ int fr_pair_raw_afrom_pair(fr_pair_t *vp, uint8_t const *data, size_t data_len)
619619
unknown = fr_dict_attr_unknown_afrom_da(vp, vp->da);
620620
if (!unknown) return -1;
621621

622+
fr_value_box_clear(&vp->data);
623+
622624
vp->da = unknown;
623625
fr_assert(vp->da->type == FR_TYPE_OCTETS);
624626

625-
fr_value_box_init(&vp->data, FR_TYPE_OCTETS, NULL, true);
626-
627-
fr_pair_value_memdup(vp, data, data_len, true);
628-
629-
return 0;
627+
return fr_value_box_memdup(vp, &vp->data, NULL, data, data_len, true);
630628
}
631629

632630
/** Iterate over pairs with a specified da
@@ -1167,7 +1165,7 @@ fr_pair_t *_fr_pair_dcursor_by_da_init(fr_dcursor_t *cursor,
11671165
*
11681166
* @param[in] cursor to initialise.
11691167
* @param[in] list to iterate over.
1170-
* @param[in] da who's decentness to search for.
1168+
* @param[in] da who's descendants to search for.
11711169
* @param[in] is_const whether the fr_pair_list_t is const.
11721170
* @return
11731171
* - The first matching pair.
@@ -2299,7 +2297,7 @@ bool fr_pair_immutable(fr_pair_t const *vp)
22992297
continue;
23002298
}
23012299

2302-
fr_assert(fr_type_is_structural(vp->vp_type));
2300+
fr_assert(fr_type_is_structural(child->vp_type));
23032301

23042302
if (fr_pair_immutable(child)) return true;
23052303
}
@@ -2473,6 +2471,7 @@ int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to,
24732471
{
24742472
fr_pair_t *tlv;
24752473
bool found = false;
2474+
fr_pair_list_t list;
24762475

24772476
if (!fr_type_is_structural(parent_da->type)) return -1;
24782477

@@ -2491,18 +2490,25 @@ int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to,
24912490
return 1;
24922491
}
24932492

2493+
fr_pair_list_init(&list);
2494+
24942495
fr_pair_list_foreach(from, vp) {
24952496
fr_pair_t *new_vp;
24962497

24972498
if (!fr_dict_attr_common_parent(parent_da, vp->da, true)) continue;
24982499

24992500
new_vp = fr_pair_copy(ctx, vp);
2500-
if (unlikely(!new_vp)) return -1;
2501+
if (unlikely(!new_vp)) {
2502+
fr_pair_list_free(&list);
2503+
return -1;
2504+
}
25012505

2502-
fr_pair_append(to, new_vp);
2506+
fr_pair_append(&list, new_vp);
25032507
found = true;
25042508
}
25052509

2510+
fr_pair_list_append(to, &list);
2511+
25062512
return found;
25072513
}
25082514

@@ -2527,18 +2533,28 @@ int fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to,
25272533
fr_pair_t const *vp;
25282534
fr_pair_t *new_vp;
25292535
unsigned int cnt = 0;
2536+
fr_pair_list_t list;
2537+
2538+
fr_pair_list_init(&list);
25302539

25312540
if (!start) start = fr_pair_list_head(from);
25322541

25332542
for (vp = start;
25342543
vp && ((count == 0) || (cnt < count));
25352544
vp = fr_pair_list_next(from, vp), cnt++) {
25362545
PAIR_VERIFY_WITH_LIST(from, vp);
2546+
25372547
new_vp = fr_pair_copy(ctx, vp);
2538-
if (unlikely(!new_vp)) return -1;
2539-
fr_pair_append(to, new_vp);
2548+
if (unlikely(!new_vp)) {
2549+
fr_pair_list_free(&list);
2550+
return -1;
2551+
}
2552+
2553+
fr_pair_append(&list, new_vp);
25402554
}
25412555

2556+
fr_pair_list_append(to, &list);
2557+
25422558
return cnt;
25432559
}
25442560

@@ -3122,7 +3138,7 @@ void fr_pair_verify(char const *file, int line, fr_dict_attr_t const *parent_da,
31223138
fr_fatal_assert_msg(vp->da->parent == parent_da,
31233139
"CONSISTENCY CHECK FAILED %s[%d]: pair %s does not have the correct parentage - "
31243140
"expected parent %s, found different parent %s",
3125-
file, line, vp->da->name, vp->da->parent->name, parent_da->name);
3141+
file, line, vp->da->name, parent_da->name, vp->da->parent->name);
31263142
}
31273143

31283144
if (list) {
@@ -3258,7 +3274,7 @@ void fr_pair_verify(char const *file, int line, fr_dict_attr_t const *parent_da,
32583274
}
32593275
if (vp->vp_ip.prefix != 32) {
32603276
fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%d]: fr_pair_t \"%s\" address prefix "
3261-
"set correctly for IPv4 address. Expected %i got %i",
3277+
"not set correctly for IPv4 address. Expected %i got %i",
32623278
file, line, vp->da->name,
32633279
32, vp->vp_ip.prefix);
32643280
}
@@ -3324,22 +3340,6 @@ void fr_pair_verify(char const *file, int line, fr_dict_attr_t const *parent_da,
33243340
if (vp->da->flags.is_unknown || vp->vp_raw) {
33253341
(void) talloc_get_type_abort_const(vp->da, fr_dict_attr_t);
33263342

3327-
} else {
3328-
fr_dict_attr_t const *da;
3329-
3330-
da = vp->da;
3331-
if (da != vp->da) {
3332-
fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%d]: fr_pair_t "
3333-
"dictionary pointer %p \"%s\" (%s) "
3334-
"and global dictionary pointer %p \"%s\" (%s) differ",
3335-
file, line, vp->da, vp->da->name,
3336-
fr_type_to_str(vp->vp_type),
3337-
da, da->name,
3338-
fr_type_to_str(da->type));
3339-
}
3340-
}
3341-
3342-
if (vp->vp_raw || vp->da->flags.is_unknown) {
33433343
/*
33443344
* Raw or unknown attributes can have specific data types. See DER and CBOR.
33453345
*/

0 commit comments

Comments
 (0)