Skip to contentSkip to conversation

dns: Limit AFSDB/SRV records to MAX_VLS

PATCH New Shaomin Chen 1 participant 1 message May 18 Keys/keyrings

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dns: Limit AFSDB/SRV records to MAX_VLS

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.

---
 dns.afsdb.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
dns.afsdb.c +10 -0
index 986c0f3..983e7cd 100644
@@ -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");
Signature · 1 line
2.47.3