From 8833d90292a9057c85f1d428a2f3418509cf6abb Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 19 Aug 2021 11:09:45 +1000 Subject: [PATCH] Reject zero length ALPN elements in fromwire --- lib/dns/rdata/in_1/svcb_64.c | 2 +- lib/dns/tests/rdata_test.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/dns/rdata/in_1/svcb_64.c b/lib/dns/rdata/in_1/svcb_64.c index 8fbb99c7b7..e1cf27c1b7 100644 --- a/lib/dns/rdata/in_1/svcb_64.c +++ b/lib/dns/rdata/in_1/svcb_64.c @@ -121,7 +121,7 @@ svcb_validate(uint16_t key, isc_region_t *region) { } while (region->length != 0) { size_t l = *region->base + 1; - if (l > region->length) { + if (l == 1U || l > region->length) { return (DNS_R_FORMERR); } isc_region_consume(region, l); diff --git a/lib/dns/tests/rdata_test.c b/lib/dns/tests/rdata_test.c index 595fcf9dac..d64ffce789 100644 --- a/lib/dns/tests/rdata_test.c +++ b/lib/dns/tests/rdata_test.c @@ -2723,6 +2723,11 @@ https_svcb(void **state) { * no-default-alpn (0x00 0x02) without alpn, alpn is required. */ WIRE_INVALID(0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00), + /* + * Alpn(0x00 0x01) with zero length elements is invalid + */ + WIRE_INVALID(0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00), WIRE_SENTINEL() }; /* Test vectors from RFCXXXX */