]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
check for fixed-size fields
authorAlan T. DeKok <aland@freeradius.org>
Thu, 24 Oct 2019 13:57:17 +0000 (09:57 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 24 Oct 2019 14:00:08 +0000 (10:00 -0400)
src/lib/util/struct.c
src/tests/unit/dhcpv6.txt

index cc7d6bd9a91d20e40c7ffd721911969b9bafcfc0..4bd40ed7bff5c664470ec4e71ee43f760efe5a9c 100644 (file)
@@ -271,10 +271,30 @@ ssize_t fr_struct_to_network(uint8_t *out, size_t outlen,
                }
 
                /*
-                *      Determine the nested type and call the appropriate encoder
+                *      Encode fixed-size octets fields so that they
+                *      are exactly the fixed size, UNLESS the entire
+                *      output is truncated.
                 */
-               len = fr_value_box_to_network(NULL, p, outlen, &vp->data);
-               if (len <= 0) return -1;
+               if ((vp->da->type == FR_TYPE_OCTETS) && vp->da->flags.length) {
+                       size_t mylen = vp->da->flags.length;
+
+                       if (mylen > outlen) mylen = outlen;
+
+                       if (vp->vp_length < mylen) {
+                               memcpy(p, vp->vp_ptr, vp->vp_length);
+                               memset(p + vp->vp_length, 0, mylen - vp->vp_length);
+                       } else {
+                               memcpy(p, vp->vp_ptr, mylen);
+                       }
+                       len = mylen;
+
+               } else {
+                       /*
+                        *      Determine the nested type and call the appropriate encoder
+                        */
+                       len = fr_value_box_to_network(NULL, p, outlen, &vp->data);
+                       if (len <= 0) return -1;
+               }
 
                if (child->flags.extra) {
                        key_da = child;
index 7588f808fced7f69458b8ea7308efc7cbe8d807e..a49a9a6cb6d06bcb617b73ef875e536c0d0d245f 100644 (file)
@@ -179,5 +179,17 @@ match 00 21 00 22 03 77 77 77 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 03 66 74 70
 encode-pair BCMCS-Server-Domain-Name-List = "www.example.com", BCMCS-Server-Domain-Name-List = "ftp.example.com", BCMCS-Server-Domain-Name-List = "ns.example.com"
 match 00 21 00 32 03 77 77 77 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 03 66 74 70 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 02 6e 73 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00
 
+encode-pair Client-ID-DUID = Client-ID-DUID-UUID, Client-ID-DUID-UUID-Value = 0x000102030405060708090a0b0c0d0e0f
+match 00 01 00 12 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
+
+#
+#  UUID-Value field is 16 octets.  So we truncate if if it's too long, and pad it with zeros if it's too short.
+#
+encode-pair Client-ID-DUID = Client-ID-DUID-UUID, Client-ID-DUID-UUID-Value = 0x000102030405060708090a0b0c0d0e0f1112
+match 00 01 00 12 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
+
+encode-pair Client-ID-DUID = Client-ID-DUID-UUID, Client-ID-DUID-UUID-Value = 0x000102030405060708090a0b0c0d
+match 00 01 00 12 00 04 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 00 00
+
 count
-match 80
+match 86