From: Alan T. DeKok Date: Thu, 20 Apr 2023 21:07:37 +0000 (-0400) Subject: clarify labels and behaviors for encode_child() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83e3052c797a9d49a4ce26331c1c1c1a1f8b0d97;p=thirdparty%2Ffreeradius-server.git clarify labels and behaviors for encode_child() Most protocols (for now) need to be able to handle flat or nested pairs. RADIUS only handles flat pairs, as it doesn't have groups --- diff --git a/src/protocols/dhcpv4/encode.c b/src/protocols/dhcpv4/encode.c index 424c9dcb19b..ed537fc0458 100644 --- a/src/protocols/dhcpv4/encode.c +++ b/src/protocols/dhcpv4/encode.c @@ -413,12 +413,12 @@ static ssize_t encode_child(fr_dbuff_t *dbuff, */ switch (da_stack->da[depth]->type) { case FR_TYPE_TLV: - if (!da_stack->da[depth + 1]) goto do_child; + if (!da_stack->da[depth + 1]) goto do_nested_children; return encode_tlv(dbuff, da_stack, depth, cursor, encode_ctx); case FR_TYPE_VSA: - if (!da_stack->da[depth + 1]) goto do_child; + if (!da_stack->da[depth + 1]) goto do_nested_children; return encode_vsio(dbuff, da_stack, depth, cursor, encode_ctx); @@ -440,7 +440,7 @@ static ssize_t encode_child(fr_dbuff_t *dbuff, } } -do_child: +do_nested_children: fr_pair_dcursor_init(&child_cursor, &vp->vp_group); work_dbuff = FR_DBUFF(dbuff); diff --git a/src/protocols/dhcpv6/encode.c b/src/protocols/dhcpv6/encode.c index 74af039fb91..ac0e4da9066 100644 --- a/src/protocols/dhcpv6/encode.c +++ b/src/protocols/dhcpv6/encode.c @@ -389,17 +389,17 @@ static ssize_t encode_child(fr_dbuff_t *dbuff, */ switch (da_stack->da[depth]->type) { case FR_TYPE_TLV: - if (!da_stack->da[depth + 1]) goto do_child; + if (!da_stack->da[depth + 1]) goto do_nested_children; return encode_tlv(dbuff, da_stack, depth, cursor, encode_ctx); case FR_TYPE_VSA: - if (!da_stack->da[depth + 1]) goto do_child; + if (!da_stack->da[depth + 1]) goto do_nested_children; return encode_vsio(dbuff, da_stack, depth, cursor, encode_ctx); case FR_TYPE_GROUP: - if (!da_stack->da[depth + 1]) goto do_child; + if (!da_stack->da[depth + 1]) goto do_nested_children; FALL_THROUGH; default: @@ -420,7 +420,7 @@ static ssize_t encode_child(fr_dbuff_t *dbuff, } } -do_child: +do_nested_children: fr_pair_dcursor_init(&child_cursor, &vp->vp_group); work_dbuff = FR_DBUFF(dbuff); diff --git a/src/protocols/dns/encode.c b/src/protocols/dns/encode.c index d1f063bad27..3e479e64a85 100644 --- a/src/protocols/dns/encode.c +++ b/src/protocols/dns/encode.c @@ -243,12 +243,12 @@ static ssize_t encode_child(fr_dbuff_t *dbuff, */ switch (da_stack->da[depth]->type) { case FR_TYPE_TLV: - if (!da_stack->da[depth + 1]) goto do_child; + if (!da_stack->da[depth + 1]) goto do_nested_children; return encode_tlv(dbuff, da_stack, depth, cursor, encode_ctx); case FR_TYPE_GROUP: - if (!da_stack->da[depth + 1]) goto do_child; + if (!da_stack->da[depth + 1]) goto do_nested_children; FALL_THROUGH; default: @@ -269,7 +269,7 @@ static ssize_t encode_child(fr_dbuff_t *dbuff, } } -do_child: +do_nested_children: fr_pair_dcursor_init(&child_cursor, &vp->vp_group); work_dbuff = FR_DBUFF(dbuff); diff --git a/src/protocols/radius/encode.c b/src/protocols/radius/encode.c index f6963309f59..e5c0ad9de5f 100644 --- a/src/protocols/radius/encode.c +++ b/src/protocols/radius/encode.c @@ -910,6 +910,9 @@ static ssize_t encode_child(fr_dbuff_t *dbuff, hlen = 2; FR_DBUFF_IN_BYTES_RETURN(&work_dbuff, (uint8_t)da_stack->da[depth]->attr, hlen); + fr_assert(da_stack->da[depth] != NULL); + fr_assert(fr_type_is_leaf(da_stack->da[depth]->type)); + slen = encode_value(&work_dbuff, da_stack, depth, cursor, encode_ctx); if (slen <= 0) return slen;