Skip to content

Commit 258aa39

Browse files
committed
ensure that unknown DA's aren't parented from the NULL ctx
and add assertion to that effect in the dictionary ext handler. This avoids memory leaks when the callers aren't careful about passing in the correct ctx.
1 parent e871034 commit 258aa39

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/lib/server/tmpl_eval.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,8 +1459,6 @@ static int _tmpl_global_free(UNUSED void *uctx)
14591459
{
14601460
fr_dict_autofree(tmpl_dict);
14611461

1462-
fr_dict_attr_unknown_free(&tmpl_attr_unspec);
1463-
14641462
return 0;
14651463
}
14661464

@@ -1473,7 +1471,7 @@ static int _tmpl_global_init(UNUSED void *uctx)
14731471
return -1;
14741472
}
14751473

1476-
da = fr_dict_attr_unknown_raw_afrom_num(NULL, fr_dict_root(dict_freeradius), 0);
1474+
da = fr_dict_attr_unknown_raw_afrom_num(UNCONST(TALLOC_CTX *, dict_freeradius), fr_dict_root(dict_freeradius), 0);
14771475
fr_assert(da != NULL);
14781476

14791477
da->type = FR_TYPE_NULL;

src/lib/server/tmpl_tokenize.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,8 @@ static inline int tmpl_attr_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t
19561956
if (fr_sbuff_out(NULL, &oid, name) > 0) {
19571957
namespace = fr_dict_unlocal(namespace);
19581958

1959+
fr_assert(ar == NULL);
1960+
19591961
fr_strerror_clear(); /* Clear out any existing errors */
19601962

19611963
if (fr_dict_by_da(namespace) == fr_dict_internal()) goto disallow_unknown;
@@ -1981,6 +1983,7 @@ static inline int tmpl_attr_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t
19811983
* then we create an unknown attribute with
19821984
* the specified attribute number.
19831985
*/
1986+
MEM(ar = talloc(ctx, tmpl_attr_t));
19841987

19851988
/*
19861989
* VSAs have VENDORs as children. All others are just normal things.
@@ -2000,7 +2003,6 @@ static inline int tmpl_attr_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t
20002003
goto error;
20012004
}
20022005

2003-
MEM(ar = talloc(ctx, tmpl_attr_t));
20042006
*ar = (tmpl_attr_t){
20052007
.ar_num = NUM_UNSPEC,
20062008
.ar_type = TMPL_ATTR_TYPE_UNKNOWN,

src/lib/util/ext.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ void *fr_ext_alloc_size(fr_ext_t const *def, void **chunk_p, int ext, size_t ext
6666
uint8_t *ext_ptr;
6767
char const *type;
6868

69+
fr_assert(chunk != NULL);
70+
fr_assert(talloc_parent(chunk) != NULL);
71+
6972
ext_offsets = fr_ext_offsets(def, *chunk_p);
7073
if (ext_offsets[ext]) return fr_ext_ptr(*chunk_p, ext_offsets[ext], info->has_hdr);
7174

src/lib/util/pair_legacy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fr_slen_t fr_pair_list_afrom_substr(fr_pair_parse_t const *root, fr_pair_parse_t
344344
}
345345
}
346346

347-
slen = fr_dict_attr_unknown_afrom_oid_substr(NULL, &da_unknown, relative->da, &our_in, raw_type);
347+
slen = fr_dict_attr_unknown_afrom_oid_substr(root->ctx, &da_unknown, relative->da, &our_in, raw_type);
348348
if (slen < 0) return fr_sbuff_error(&our_in) + slen;
349349

350350
fr_assert(da_unknown);
@@ -454,7 +454,7 @@ fr_slen_t fr_pair_list_afrom_substr(fr_pair_parse_t const *root, fr_pair_parse_t
454454
return fr_sbuff_error(&our_in);
455455
}
456456

457-
da_unknown = fr_dict_attr_unknown_raw_afrom_da(NULL, da);
457+
da_unknown = fr_dict_attr_unknown_raw_afrom_da(root->ctx, da);
458458
if (!da_unknown) return fr_sbuff_error(&our_in);
459459

460460
fr_assert(da_unknown->type == FR_TYPE_OCTETS);

0 commit comments

Comments
 (0)