diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2019-07-19 18:16:39 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2019-07-19 20:10:38 +0200 |
commit | ed91ec54fcc777d8b5f9fb32f78bf14c4e8ea343 (patch) | |
tree | 9d82f66b9d9e0fdbe5367bce83465129684248b3 /main/openssh/fix-verify-dns-segfault.patch | |
parent | bf8d905764917d140c05af013574051809056da0 (diff) |
main/openssh: fix segfault with VerifyHostKeyDNS=yes
fix a case in openbsd-compat where there are no DNS answers. Apparently
OpenBSD returns ancount=0 but the answer struct is non NULL, while with
musl the answer is NULL.
fixes #8323
Diffstat (limited to 'main/openssh/fix-verify-dns-segfault.patch')
-rw-r--r-- | main/openssh/fix-verify-dns-segfault.patch | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/main/openssh/fix-verify-dns-segfault.patch b/main/openssh/fix-verify-dns-segfault.patch new file mode 100644 index 00000000000..11b65c28971 --- /dev/null +++ b/main/openssh/fix-verify-dns-segfault.patch @@ -0,0 +1,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); + |