aboutsummaryrefslogtreecommitdiffstats
path: root/main/openssh/fix-verify-dns-segfault.patch
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2019-07-19 18:16:39 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2019-07-19 20:10:38 +0200
commited91ec54fcc777d8b5f9fb32f78bf14c4e8ea343 (patch)
tree9d82f66b9d9e0fdbe5367bce83465129684248b3 /main/openssh/fix-verify-dns-segfault.patch
parentbf8d905764917d140c05af013574051809056da0 (diff)
downloadaports-ed91ec54fcc777d8b5f9fb32f78bf14c4e8ea343.tar.gz
aports-ed91ec54fcc777d8b5f9fb32f78bf14c4e8ea343.tar.bz2
aports-ed91ec54fcc777d8b5f9fb32f78bf14c4e8ea343.tar.xz
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.patch57
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 0000000000..11b65c2897
--- /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);
+