From b6d9d4f7a6f5724a6302c69b1e4696b06d6650cc Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Fri, 14 Nov 2025 12:59:29 +1100 Subject: [PATCH] AMTRELAY type 0 presentation format handling was wrong RFC 8777 specifies a placeholder value of "." for the gateway field when the gateway type is 0 (no gateway). (cherry picked from commit ae484d450128658dd8fea9455c330095327c0e21) --- ...-atmrelay.db => bad-cname-and-amtrelay.db} | 2 +- bin/tests/system/doth/example.axfr.good | 4 +-- bin/tests/system/doth/example8.axfr.good | 4 +-- bin/tests/system/genzone.sh | 4 +-- bin/tests/system/xfer/dig1.good | 4 +-- bin/tests/system/xfer/dig2.good | 4 +-- lib/dns/rdata/generic/amtrelay_260.c | 26 +++++++++---------- tests/dns/rdata_test.c | 10 ++++--- 8 files changed, 30 insertions(+), 28 deletions(-) rename bin/tests/system/checkzone/zones/{bad-cname-and-atmrelay.db => bad-cname-and-amtrelay.db} (95%) diff --git a/bin/tests/system/checkzone/zones/bad-cname-and-atmrelay.db b/bin/tests/system/checkzone/zones/bad-cname-and-amtrelay.db similarity index 95% rename from bin/tests/system/checkzone/zones/bad-cname-and-atmrelay.db rename to bin/tests/system/checkzone/zones/bad-cname-and-amtrelay.db index dc193af66b..7c2aab2449 100644 --- a/bin/tests/system/checkzone/zones/bad-cname-and-atmrelay.db +++ b/bin/tests/system/checkzone/zones/bad-cname-and-amtrelay.db @@ -13,5 +13,5 @@ $TTL 600 @ SOA ns hostmaster 2011012708 3600 1200 604800 1200 NS ns ns A 192.0.2.1 -bad ATMRELAY 0 0 0 +bad AMTRELAY 0 0 0 . bad CNAME @ diff --git a/bin/tests/system/doth/example.axfr.good b/bin/tests/system/doth/example.axfr.good index d9e3cbf68e..cf14b43d88 100644 --- a/bin/tests/system/doth/example.axfr.good +++ b/bin/tests/system/doth/example.axfr.good @@ -11,8 +11,8 @@ aaaa01.example. 3600 IN AAAA ::1 aaaa02.example. 3600 IN AAAA fd92:7065:b8e:ffff::5 afsdb01.example. 3600 IN AFSDB 0 hostname.example. afsdb02.example. 3600 IN AFSDB 65535 . -amtrelay01.example. 3600 IN AMTRELAY 0 0 0 -amtrelay02.example. 3600 IN AMTRELAY 0 1 0 +amtrelay01.example. 3600 IN AMTRELAY 0 0 0 . +amtrelay02.example. 3600 IN AMTRELAY 0 1 0 . amtrelay03.example. 3600 IN AMTRELAY 0 0 1 0.0.0.0 amtrelay04.example. 3600 IN AMTRELAY 0 0 2 :: amtrelay05.example. 3600 IN AMTRELAY 0 0 3 example.net. diff --git a/bin/tests/system/doth/example8.axfr.good b/bin/tests/system/doth/example8.axfr.good index 445653f394..ba3ef87221 100644 --- a/bin/tests/system/doth/example8.axfr.good +++ b/bin/tests/system/doth/example8.axfr.good @@ -11,8 +11,8 @@ aaaa01.example8. 3600 IN AAAA ::1 aaaa02.example8. 3600 IN AAAA fd92:7065:b8e:ffff::5 afsdb01.example8. 3600 IN AFSDB 0 hostname.example8. afsdb02.example8. 3600 IN AFSDB 65535 . -amtrelay01.example8. 3600 IN AMTRELAY 0 0 0 -amtrelay02.example8. 3600 IN AMTRELAY 0 1 0 +amtrelay01.example8. 3600 IN AMTRELAY 0 0 0 . +amtrelay02.example8. 3600 IN AMTRELAY 0 1 0 . amtrelay03.example8. 3600 IN AMTRELAY 0 0 1 0.0.0.0 amtrelay04.example8. 3600 IN AMTRELAY 0 0 2 :: amtrelay05.example8. 3600 IN AMTRELAY 0 0 3 example.net. diff --git a/bin/tests/system/genzone.sh b/bin/tests/system/genzone.sh index 6762efd290..70b4a9cf02 100644 --- a/bin/tests/system/genzone.sh +++ b/bin/tests/system/genzone.sh @@ -487,8 +487,8 @@ doa01 DOA ( 1234567890 1234567890 1 "image/gif" doa02 DOA 0 1 2 "" aHR0cHM6Ly93d3cuaXNjLm9yZy8= ; type 260 -amtrelay01 AMTRELAY 0 0 0 -amtrelay02 AMTRELAY 0 1 0 +amtrelay01 AMTRELAY 0 0 0 . +amtrelay02 AMTRELAY 0 1 0 . amtrelay03 AMTRELAY 0 0 1 0.0.0.0 amtrelay04 AMTRELAY 0 0 2 :: amtrelay05 AMTRELAY 0 0 3 example.net. diff --git a/bin/tests/system/xfer/dig1.good b/bin/tests/system/xfer/dig1.good index dd0feed753..06f9790d40 100644 --- a/bin/tests/system/xfer/dig1.good +++ b/bin/tests/system/xfer/dig1.good @@ -12,8 +12,8 @@ aaaa01.example. 3600 IN AAAA ::1 aaaa02.example. 3600 IN AAAA fd92:7065:b8e:ffff::5 afsdb01.example. 3600 IN AFSDB 0 hostname.example. afsdb02.example. 3600 IN AFSDB 65535 . -amtrelay01.example. 3600 IN AMTRELAY 0 0 0 -amtrelay02.example. 3600 IN AMTRELAY 0 1 0 +amtrelay01.example. 3600 IN AMTRELAY 0 0 0 . +amtrelay02.example. 3600 IN AMTRELAY 0 1 0 . amtrelay03.example. 3600 IN AMTRELAY 0 0 1 0.0.0.0 amtrelay04.example. 3600 IN AMTRELAY 0 0 2 :: amtrelay05.example. 3600 IN AMTRELAY 0 0 3 example.net. diff --git a/bin/tests/system/xfer/dig2.good b/bin/tests/system/xfer/dig2.good index 880368c603..1c1c60e404 100644 --- a/bin/tests/system/xfer/dig2.good +++ b/bin/tests/system/xfer/dig2.good @@ -12,8 +12,8 @@ aaaa01.example. 3600 IN AAAA ::1 aaaa02.example. 3600 IN AAAA fd92:7065:b8e:ffff::5 afsdb01.example. 3600 IN AFSDB 0 hostname.example. afsdb02.example. 3600 IN AFSDB 65535 . -amtrelay01.example. 3600 IN AMTRELAY 0 0 0 -amtrelay02.example. 3600 IN AMTRELAY 0 1 0 +amtrelay01.example. 3600 IN AMTRELAY 0 0 0 . +amtrelay02.example. 3600 IN AMTRELAY 0 1 0 . amtrelay03.example. 3600 IN AMTRELAY 0 0 1 0.0.0.1 amtrelay04.example. 3600 IN AMTRELAY 0 0 2 :: amtrelay05.example. 3600 IN AMTRELAY 0 0 3 example.net. diff --git a/lib/dns/rdata/generic/amtrelay_260.c b/lib/dns/rdata/generic/amtrelay_260.c index 6825874cb9..0f5be31f24 100644 --- a/lib/dns/rdata/generic/amtrelay_260.c +++ b/lib/dns/rdata/generic/amtrelay_260.c @@ -68,21 +68,22 @@ fromtext_amtrelay(ARGS_FROMTEXT) { RETERR(uint8_tobuffer(token.value.as_ulong | (discovery << 7), target)); gateway = token.value.as_ulong; - if (gateway == 0) { - return ISC_R_SUCCESS; - } + /* + * Gateway (must exist). + */ + RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, + false)); if (gateway > 3) { return ISC_R_NOTIMPLEMENTED; } - /* - * Gateway. - */ - RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, - false)); - switch (gateway) { + case 0: + if (strcmp(DNS_AS_STR(token), ".") != 0) { + RETTOK(DNS_R_SYNTAX); + } + return ISC_R_SUCCESS; case 1: if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) { RETTOK(DNS_R_BADDOTTEDQUAD); @@ -128,7 +129,6 @@ totext_amtrelay(ARGS_TOTEXT) { unsigned char precedence; unsigned char discovery; unsigned char gateway; - const char *space; UNUSED(tctx); @@ -154,9 +154,8 @@ totext_amtrelay(ARGS_TOTEXT) { gateway = uint8_fromregion(®ion); discovery = gateway >> 7; gateway &= 0x7f; - space = (gateway != 0U) ? " " : ""; isc_region_consume(®ion, 1); - snprintf(buf, sizeof(buf), "%u %u%s", discovery, gateway, space); + snprintf(buf, sizeof(buf), "%u %u ", discovery, gateway); RETERR(str_totext(buf, target)); /* @@ -164,7 +163,8 @@ totext_amtrelay(ARGS_TOTEXT) { */ switch (gateway) { case 0: - break; + return str_totext(".", target); + case 1: return inet_totext(AF_INET, tctx->flags, ®ion, target); diff --git a/tests/dns/rdata_test.c b/tests/dns/rdata_test.c index e59e6662e7..ca749b8bdd 100644 --- a/tests/dns/rdata_test.c +++ b/tests/dns/rdata_test.c @@ -1024,11 +1024,13 @@ ISC_RUN_TEST_IMPL(atma) { ISC_RUN_TEST_IMPL(amtrelay) { text_ok_t text_ok[] = { TEXT_INVALID(""), TEXT_INVALID("0"), TEXT_INVALID("0 0"), + TEXT_INVALID("0 0 0"), /* gateway type 0 */ - TEXT_VALID("0 0 0"), TEXT_VALID("0 1 0"), - TEXT_INVALID("0 2 0"), /* discovery out of range */ - TEXT_VALID("255 1 0"), /* max precedence */ - TEXT_INVALID("256 1 0"), /* precedence out of range */ + TEXT_INVALID("0 0 0 x"), /* bad placeholder */ + TEXT_VALID("0 0 0 ."), TEXT_VALID("0 1 0 ."), + TEXT_INVALID("0 2 0 ."), /* discovery out of range */ + TEXT_VALID("255 1 0 ."), /* max precedence */ + TEXT_INVALID("256 1 0 ."), /* precedence out of range */ /* IPv4 gateway */ TEXT_INVALID("0 0 1"), /* no address */