]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
arrays of string/octets are encoded as 16-bit length + data
authorAlan T. DeKok <aland@freeradius.org>
Fri, 13 Aug 2021 17:42:18 +0000 (13:42 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 13 Aug 2021 17:53:29 +0000 (13:53 -0400)
which are fixed size.

And, clamp the maximum encoded value to 16-bits, too

src/protocols/dhcpv6/base.c

index 12537f83bace6d91dad145e2673080ce666c6b06..03f0a8971acef1b76259f8c57f89d9f423a3f4ef 100644 (file)
@@ -161,6 +161,14 @@ size_t fr_dhcpv6_option_len(fr_pair_t const *vp)
 #endif
 
                if (vp->da->flags.length) return vp->da->flags.length;  /* Variable type with fixed length */
+
+               /*
+                *      Arrays get maxed at 2^16-1
+                */
+               if (vp->da->flags.array && ((vp->vp_type == FR_TYPE_STRING) || (vp->vp_type == FR_TYPE_OCTETS))) {
+                       if (vp->vp_length > 65535) return 65535;
+               }
+
                return vp->vp_length;
 
        case FR_TYPE_DATE:
@@ -1020,6 +1028,14 @@ void fr_dhcpv6_global_free(void)
 static bool attr_valid(UNUSED fr_dict_t *dict, UNUSED fr_dict_attr_t const *parent,
                       UNUSED char const *name, UNUSED int attr, fr_type_t type, fr_dict_attr_flags_t *flags)
 {
+       /*
+        *      "arrays" of string/octets are encoded as a 16-bit
+        *      length, followed by the actual data.
+        */
+       if (flags->array && ((type == FR_TYPE_STRING) || (type == FR_TYPE_OCTETS))) {
+               flags->is_known_width = true;
+       }
+
        /*
         *      "extra" signifies that subtype is being used by the
         *      dictionaries itself.