aboutsummaryrefslogtreecommitdiffstats
path: root/main/openssh/fix-verify-dns-segfault.patch
blob: 11b65c289714f8a6271f01dd708b66cecb368de9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Handle case when answer=NULL due to zero answers

diff --git a/openbsd-compat/getrrsetbyname.c b/openbsd-compat/getrrsetbyname.c
index dc6fe05..28622b5 100644
--- a/openbsd-compat/getrrsetbyname.c
+++ b/openbsd-compat/getrrsetbyname.c
@@ -268,7 +268,7 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
 	}
 	rrset->rri_rdclass = response->query->class;
 	rrset->rri_rdtype = response->query->type;
-	rrset->rri_ttl = response->answer->ttl;
+	rrset->rri_ttl = response->answer ? response->answer->ttl : 0;
 	rrset->rri_nrdatas = response->header.ancount;
 
 #ifdef HAVE_HEADER_AD
@@ -276,6 +276,17 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
 	if (response->header.ad == 1)
 		rrset->rri_flags |= RRSET_VALIDATED;
 #endif
+	/* allocate memory for signatures */
+	if (rrset->rri_nsigs > 0) {
+		rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo));
+		if (rrset->rri_sigs == NULL) {
+			result = ERRSET_NOMEMORY;
+			goto fail;
+		}
+	}
+
+	if (response->answer == NULL || response->header.ancount == 0)
+		goto done;
 
 	/* copy name from answer section */
 	rrset->rri_name = strdup(response->answer->name);
@@ -298,15 +309,6 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
 		goto fail;
 	}
 
-	/* allocate memory for signatures */
-	if (rrset->rri_nsigs > 0) {
-		rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo));
-		if (rrset->rri_sigs == NULL) {
-			result = ERRSET_NOMEMORY;
-			goto fail;
-		}
-	}
-
 	/* copy answers & signatures */
 	for (rr = response->answer, index_ans = 0, index_sig = 0;
 	    rr; rr = rr->next) {
@@ -334,6 +336,7 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
 	}
 	free_dns_response(response);
 
+done:
 	*res = rrset;
 	return (ERRSET_SUCCESS);