]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
don't bother checking chaddr size during decode
authorAlan T. DeKok <aland@freeradius.org>
Fri, 8 Sep 2023 17:25:46 +0000 (13:25 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 8 Sep 2023 20:08:54 +0000 (16:08 -0400)
fr_dhcpv4_ok() checks if htype==1 && hlen==6, and fails if that
isn't true.

So either that test passed, or the caller didn't call fr_dhcpv4_ok()
to verify the packet.  In either case, there's no reason to do
additional validation here.

src/protocols/dhcpv4/packet.c
src/tests/unit/protocols/dhcpv4/error.txt

index 4c8eb31460bd941204e70e3d045498ff7bc665a3..0a3951f7da2e141b852849e6b8ec91bec6863a38 100644 (file)
@@ -136,21 +136,6 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data,
                        return -1;
                }
 
-               /*
-                *      If chaddr != 6 bytes it's probably not ethernet, and we should store
-                *      it as an opaque type (octets).
-                */
-               if (da == attr_dhcp_client_hardware_address) {
-                       /*
-                        *      Skip chaddr if it doesn't exist.
-                        */
-                       if ((data[1] == 0) || (data[2] == 0)) continue;
-
-                       if ((data[1] == 1) && (data[2] != sizeof(vp->vp_ether))) {
-                               fr_pair_to_unknown(vp);
-                       }
-               }
-
                switch (vp->vp_type) {
                case FR_TYPE_STRING:
                        /*
@@ -166,18 +151,17 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data,
                        if (vp->vp_length == 0) TALLOC_FREE(vp);
                        break;
 
-               case FR_TYPE_OCTETS:
-                       if (data[2] == 0) break;
-
-                       fr_pair_value_memdup(vp, p, data[2], true);
-                       break;
-
                        /*
                         *      The DHCP header size for CHADDR is not
                         *      6, so the value_box function doesn't
                         *      like it.  Just do the copy manually.
                         */
                case FR_TYPE_ETHERNET:
+                       if ((data[1] != 1) || (data[2] != 6)) {
+                               TALLOC_FREE(vp);
+                               break;
+                       }
+
                        memcpy(vp->vp_ether, p, sizeof(vp->vp_ether));
                        break;
 
index 87dacd9244696adea8f02ecfaf86583fc8e58792..163b4eb4af30972700aca81c12fd7638e4fa5447 100644 (file)
@@ -12,7 +12,7 @@ decode-pair 7d 00
 match raw.V-I-Vendor-Specific = 0x
 
 decode-proto 03 00 00 f5 00 11 41 04 04 04 04 04 29 04 04 00 04 ca 04 04 04 09 04 04 1a f3 ff 7e a0 b5 25 07 80 3b 60 00 00 1a 23 00 00 fd 00 80 00 00 00 00 00 10 00 80 00 00 00 00 00 00 2f 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fa 67 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ca 04 04 04 04 04 04 1a 0d 00 00 60 b5 25 07 2b 35 60 00 00 1a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f7 00 00 00 00 00 00 11 00 00 00 00 00 32 60 1a 00 08 0d 00 00 60 b5 00 00 00 25 21 39 21 1a 0d 00 00 60 b5 25 07 80 34 60 00 00 1a 0d 00 00 60 b5 25 2a 60 00 31 00 80 1a 0d 00 00 60 b5 25 07 80 34 21 21 04 1a 0d 00 00 60 63 82 53 63 f2 60 b5 25 07 80 31 60 00 00 1a 29 00 00 00 f8 ff ff fc 00 00 00 00 00 00 04 00 00 00 d6 00 00 5d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ca 04 04 04 04 04 04 1a 0d 00 00 60 b5 25 07 80 34 65 00 00 1a 00 00 00 00 00 00 00 00 00 00 00 1a 0d 00 00 20 b5 25 07 80 35 2f 04 00 00 00 00 ff fb 00 00 00 00 00 00 00 00 00 00 00 04 00 04 0d 7a 7a 7a 7a 00 10 00 00 00 00 00 00 d5 10 00 00 00 00 00 00 00 00 00 02 00 7d 00 00 00 00 00
-match Opcode = 3, Hardware-Type = 0, Hardware-Address-Length = 0, Hop-Count = 245, Transaction-Id = 1130756, Number-of-Seconds = 1028, Flags = 1028, Client-IP-Address = 41.4.4.0, Your-IP-Address = 4.202.4.4, Server-IP-Address = 4.9.4.4, Gateway-IP-Address = 26.243.255.126, Server-Host-Name = "\240\265\%\a\200;`", Site-specific-18 = 0xb5250780316000001a29000000f8fffffc00000000000004000000d600005d000000000000000000000000000000000000000000000004ca0404040404041a0d000060b5250780346500001a00000000000000000000001a0d000020b5250780, raw.Message-Type = 0x0400000000fffb00000000000000000000000400040d7a7a7a7a0010000000000000d5100000000000000000000200, raw.V-I-Vendor-Specific = 0x, Network-Subnet = 26.243.255.126/32
+match Opcode = 3, Hardware-Type = 0, Hardware-Address-Length = 0, Hop-Count = 245, Transaction-Id = 1130756, Number-of-Seconds = 1028, Flags = 1028, Client-IP-Address = 41.4.4.0, Your-IP-Address = 4.202.4.4, Server-IP-Address = 4.9.4.4, Gateway-IP-Address = 26.243.255.126, Boot-Filename = "\004\004\004\004\032\r", Site-specific-18 = 0xb5250780316000001a29000000f8fffffc00000000000004000000d600005d000000000000000000000000000000000000000000000004ca0404040404041a0d000060b5250780346500001a00000000000000000000001a0d000020b5250780, raw.Message-Type = 0x0400000000fffb00000000000000000000000400040d7a7a7a7a0010000000000000d5100000000000000000000200, raw.V-I-Vendor-Specific = 0x, Network-Subnet = 26.243.255.126/32
 
 decode-pair 76 03 01 02 03
 match raw.Subnet-Selection-Option = 0x010203