From: Mark Andrews Date: Mon, 3 Aug 2026 04:42:51 +0000 (+1000) Subject: Tighten EUI48 and EUI64 text parser X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=59d2ff1920f8658b54880480b6f80a80d646c987;p=thirdparty%2Fbind9.git Tighten EUI48 and EUI64 text parser 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. --- diff --git a/lib/dns/rdata/generic/eui48_108.c b/lib/dns/rdata/generic/eui48_108.c index 604e13f7f5e..004c6aafc16 100644 --- a/lib/dns/rdata/generic/eui48_108.c +++ b/lib/dns/rdata/generic/eui48_108.c @@ -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; diff --git a/lib/dns/rdata/generic/eui64_109.c b/lib/dns/rdata/generic/eui64_109.c index 335dd5cd926..eafbfbb115b 100644 --- a/lib/dns/rdata/generic/eui64_109.c +++ b/lib/dns/rdata/generic/eui64_109.c @@ -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;