]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Tighten EUI48 and EUI64 text parser
authorMark Andrews <marka@isc.org>
Mon, 3 Aug 2026 04:42:51 +0000 (14:42 +1000)
committerMark Andrews <marka@isc.org>
Thu, 6 Aug 2026 13:22:06 +0000 (23:22 +1000)
Check that leading zeros were present and that there wasn't
any garbage at the end of the token by generating the record
in canonical form and checking that the input matched.

lib/dns/rdata/generic/eui48_108.c
lib/dns/rdata/generic/eui64_109.c

index 604e13f7f5e59dc6660419b60a55f30bd45a92c0..004c6aafc16f5364bda494a5418df819617301cd 100644 (file)
@@ -23,6 +23,7 @@ fromtext_eui48(ARGS_FROMTEXT) {
        isc_token_t token;
        unsigned char eui48[6];
        unsigned int l0, l1, l2, l3, l4, l5;
+       char buf[sizeof("xx-xx-xx-xx-xx-xx")];
        int n;
 
        REQUIRE(type == dns_rdatatype_eui48);
@@ -43,6 +44,16 @@ fromtext_eui48(ARGS_FROMTEXT) {
                return DNS_R_BADEUI;
        }
 
+       /*
+        * Check that leading zeros were present and that there wasn't
+        * trailing garbage.
+        */
+       n = snprintf(buf, sizeof(buf), "%02x-%02x-%02x-%02x-%02x-%02x", l0, l1,
+                    l2, l3, l4, l5);
+       if (n != sizeof(buf) - 1 || strcasecmp(DNS_AS_STR(token), buf) != 0) {
+               return DNS_R_BADEUI;
+       }
+
        eui48[0] = l0;
        eui48[1] = l1;
        eui48[2] = l2;
index 335dd5cd926e5bfd227ab85120ac98db10f77a25..eafbfbb115b9cd8d747e5a85c7149f9d81d4e117 100644 (file)
@@ -23,6 +23,7 @@ fromtext_eui64(ARGS_FROMTEXT) {
        isc_token_t token;
        unsigned char eui64[8];
        unsigned int l0, l1, l2, l3, l4, l5, l6, l7;
+       char buf[sizeof("xx-xx-xx-xx-xx-xx-xx-xx")];
        int n;
 
        REQUIRE(type == dns_rdatatype_eui64);
@@ -43,6 +44,17 @@ fromtext_eui64(ARGS_FROMTEXT) {
                return DNS_R_BADEUI;
        }
 
+       /*
+        * Check that leading zeros were present and that there wasn't
+        * trailing garbage.
+        */
+       n = snprintf(buf, sizeof(buf),
+                    "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", l0, l1, l2, l3,
+                    l4, l5, l6, l7);
+       if (n != sizeof(buf) - 1 || strcasecmp(DNS_AS_STR(token), buf) != 0) {
+               return DNS_R_BADEUI;
+       }
+
        eui64[0] = l0;
        eui64[1] = l1;
        eui64[2] = l2;