From: Alan T. DeKok Date: Mon, 3 Mar 2025 12:49:52 +0000 (-0500) Subject: clean up encode_oid_and_value X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70ed35b986e840563f9d44eb80636e52f53a61e7;p=thirdparty%2Ffreeradius-server.git clean up encode_oid_and_value --- diff --git a/src/protocols/der/encode.c b/src/protocols/der/encode.c index 052fe2ca96..56890d6ff8 100644 --- a/src/protocols/der/encode.c +++ b/src/protocols/der/encode.c @@ -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); }