Skip to content

Commit 67f31ce

Browse files
committed
update getrrsetbyname.c from OpenBSD upstream
revision 1.15 date: 2026/05/09 01:54:51; author: tb; state: Exp; lines: +14 -13; commitid: zZPVUWycKAslGJtO; Avoid recursive cleanup in getrrsetbyname() Instead of freeing struct dns_query and struct dns_rr by walking the linked lists recursively, use a simple loop. This avoids a possible stack exhaustion unlikely to be reachable with the limits modern resolvers impose. From Dhiraj Mishra
1 parent 56e73cd commit 67f31ce

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

openbsd-compat/getrrsetbyname.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -595,27 +595,28 @@ parse_dns_rrsection(const u_char *answer, int size, const u_char **cp,
595595
static void
596596
free_dns_query(struct dns_query *p)
597597
{
598-
if (p == NULL)
599-
return;
598+
struct dns_query *next;
600599

601-
if (p->name)
600+
while (p != NULL) {
601+
next = p->next;
602602
free(p->name);
603-
free_dns_query(p->next);
604-
free(p);
603+
free(p);
604+
p = next;
605+
}
605606
}
606607

607608
static void
608609
free_dns_rr(struct dns_rr *p)
609610
{
610-
if (p == NULL)
611-
return;
611+
struct dns_rr *next;
612612

613-
if (p->name)
613+
while (p != NULL) {
614+
next = p->next;
614615
free(p->name);
615-
if (p->rdata)
616616
free(p->rdata);
617-
free_dns_rr(p->next);
618-
free(p);
617+
free(p);
618+
p = next;
619+
}
619620
}
620621

621622
static void

0 commit comments

Comments
 (0)