From: Alan T. DeKok Date: Tue, 5 Apr 2022 12:45:44 +0000 (-0400) Subject: fix fr_pair_reinit_from_da() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0c80171bb87c90bd5ea1488ca7d7618e12f3214;p=thirdparty%2Ffreeradius-server.git fix fr_pair_reinit_from_da() it may be called with a VP which has been created via fr_pair_alloc_null(), in which case vp->da is NULL. --- diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index cdcfdd66ba..992c39cc56 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -328,17 +328,23 @@ fr_pair_t *fr_pair_afrom_da_with_pool(TALLOC_CTX *ctx, fr_dict_attr_t const *da, */ int fr_pair_reinit_from_da(fr_pair_list_t *list, fr_pair_t *vp, fr_dict_attr_t const *da) { - if (vp->da == da) return 0; - - if ((da->type != vp->da->type) && (fr_value_box_cast_in_place(vp, &vp->data, da->type, da) < 0)) return -1; + fr_dict_attr_t const *to_free; /* - * Only frees unknown fr_dict_attr_t's + * vp may be created from fr_pair_alloc_null(), in which case it has no da. */ - fr_dict_unknown_free(&vp->da); + if (vp->da) { + if (vp->da == da) return 0; + + if ((da->type != vp->da->type) && (fr_value_box_cast_in_place(vp, &vp->data, da->type, da) < 0)) return -1; + } else { + fr_value_box_init(&vp->data, da->type, da, false); + } + + to_free = vp->da; /* - * Ensure we update the attr index in the parent + * Ensure we update the attribute index in the parent. */ if (list) { fr_pair_remove(list, vp); @@ -350,6 +356,11 @@ int fr_pair_reinit_from_da(fr_pair_list_t *list, fr_pair_t *vp, fr_dict_attr_t c vp->da = da; } + /* + * Only frees unknown fr_dict_attr_t's + */ + fr_dict_unknown_free(&to_free); + return 0; }