]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clarify labels and behaviors for encode_child()
authorAlan T. DeKok <aland@freeradius.org>
Thu, 20 Apr 2023 21:07:37 +0000 (17:07 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 20 Apr 2023 21:20:21 +0000 (17:20 -0400)
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

src/protocols/dhcpv4/encode.c
src/protocols/dhcpv6/encode.c
src/protocols/dns/encode.c
src/protocols/radius/encode.c

index 424c9dcb19b0b25dcb8ac1d135bf0711559c35c3..ed537fc045822bffb63e3b3399c9c0f4bc54227c 100644 (file)
@@ -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);
 
index 74af039fb914c8ef043355a8417762186d56ca0b..ac0e4da9066cff306aff6fd81fc3e1cbe9a03e3a 100644 (file)
@@ -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);
 
index d1f063bad27e1d7403133670b6682ea144b447aa..3e479e64a85d75e1cd09f5d8ac87a843d7e25043 100644 (file)
@@ -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);
 
index f6963309f59965d43b04d292a3f09d0429f66872..e5c0ad9de5fb264e190b4ad7aadd1c990802713f 100644 (file)
@@ -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;