]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clean up encode_oid_and_value
authorAlan T. DeKok <aland@freeradius.org>
Mon, 3 Mar 2025 12:49:52 +0000 (07:49 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 3 Mar 2025 13:14:34 +0000 (08:14 -0500)
src/protocols/der/encode.c

index 052fe2ca9600fc82477e9edb84e93ef876d9bb22..56890d6ff8f2f452e4da6dc4d44ce163113b1051 100644 (file)
@@ -1448,17 +1448,12 @@ static ssize_t fr_der_encode_oid_and_value(fr_dbuff_t *dbuff, fr_dcursor_t *curs
                PAIR_VERIFY(child);
 
                /*
-                *      We stop encoding at a leaf.
+                *      If we find a normal leaf data type, we don't encode it.  But we do encode leaf data
+                *      types which are marked up as needing OID leaf encoding.
                 */
-               if (!fr_type_is_structural(child->vp_type) && !fr_der_flag_is_oid_leaf(child->da)) {
+               if (!fr_type_is_structural(child->vp_type) && !fr_der_flag_is_oid_leaf(child->da) && !child->da->flags.is_raw) {
                        FR_PROTO_TRACE("Found non-structural child %s", child->da->name);
 
-                       if (child->da->flags.is_raw) {
-                               slen = fr_der_encode_oid_from_value(&our_dbuff, child->da->attr, &component, &count);
-                               if (unlikely(slen < 0)) return -1;
-                               break;
-                       }
-
                        fr_dcursor_copy(&child_cursor, &parent_cursor);
                        break;
                }
@@ -1466,13 +1461,22 @@ static ssize_t fr_der_encode_oid_and_value(fr_dbuff_t *dbuff, fr_dcursor_t *curs
                slen = fr_der_encode_oid_from_value(&our_dbuff, child->da->attr, &component, &count);
                if (unlikely(slen < 0)) return -1;
 
+               /*
+                *      We've encoded a leaf data type, or a raw one.  Stop encoding it.
+                */
+               if (!fr_type_is_structural(child->vp_type)) break;
+
+               /*
+                *      Some structural types can be marked as a leaf for the purposes of OID encoding.
+                */
+               if (fr_der_flag_is_oid_leaf(child->da)) break;
+
                /*
                 *      Unless this was the last child (marked as an oid leaf), there should only be one child
                 *      - representing the next OID in the pair
                 */
                if (fr_pair_list_num_elements(&child->children) > 1) break;
 
-               if (fr_der_flag_is_oid_leaf(child->da)) break;
                fr_pair_dcursor_child_iter_init(&child_cursor, &child->children, &child_cursor);
        }