[PATCH keyutils] dns: Limit AFSDB/SRV records to MAX_VLS
Shaomin Chen <[email protected]> Tue, 19 May 2026 00:44:35 +0800
| Newsgroups | org.kernel.vger.keyrings |
|---|---|
| Message-ID | <[email protected]> |
afsdb_hosts_to_addrs() and srv_hosts_to_addrs() store server names in vllist[MAX_VLS], but iterate over all DNS answers without checking whether vlsnum has reached MAX_VLS. A response with more than MAX_VLS usable records can therefore write past the end of the array. Ignore additional records once MAX_VLS entries have been collected. Signed-off-by: Shaomin Chen <[email protected]> --- dns.afsdb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dns.afsdb.c b/dns.afsdb.c index 986c0f3..983e7cd 100644 --- a/dns.afsdb.c +++ b/dns.afsdb.c @@ -61,6 +61,11 @@ static void afsdb_hosts_to_addrs(ns_msg handle, ns_sect section) /* We're only interested in AFSDB records */ if (ns_rr_type(rr) == ns_t_afsdb) { + if (vlsnum >= MAX_VLS) { + debug("Too many AFSDB records, ignoring extra record"); + continue; + } + vllist[vlsnum] = malloc(MAXDNAME); if (!vllist[vlsnum]) error("Out of memory"); @@ -141,6 +146,11 @@ static void srv_hosts_to_addrs(ns_msg handle, ns_sect section) } if (ns_rr_type(rr) == ns_t_srv) { + if (vlsnum >= MAX_VLS) { + debug("Too many SRV records, ignoring extra record"); + continue; + } + vllist[vlsnum] = malloc(MAXDNAME); if (!vllist[vlsnum]) error("Out of memory"); -- 2.47.3