From 862b5d470c7b19019811963596f9da624913147d Mon Sep 17 00:00:00 2001 From: Geod24 Date: Wed, 29 Jul 2020 12:52:42 +0900 Subject: [PATCH] posix/dns: Fix SEGV on Musl when an error happens When an error happens, the 'struct addrinfo' (ai) passed to 'passToDNSCallback' can be 'null'. It end up being passed to 'freeaddrinfo'. With glibc, or on OSX, it is okay to pass a 'null' pointer to 'freeaddrinfo', however this will cause a SIGSEGV on Musl. The standard defines that 'freeaddrinfo' must accept what was given to 'getaddrinfo', and 'getaddrinfo' does not accept null pointer, so the musl behavior is not wrong per se. --- meson.build | 2 +- source/eventcore/drivers/posix/dns.d | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 5ff9505a..4a6b1950 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('eventcore', 'd', meson_version: '>=0.50', - version: '0.9.6' + version: '0.9.7' ) project_soversion = '0' diff --git a/source/eventcore/drivers/posix/dns.d b/source/eventcore/drivers/posix/dns.d index c549648f..6875a0a9 100644 --- a/source/eventcore/drivers/posix/dns.d +++ b/source/eventcore/drivers/posix/dns.d @@ -180,7 +180,14 @@ final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriver l.done = false; if (i == m_maxHandle) m_maxHandle = lastmax; m_events.loop.m_waiterCount--; - passToDNSCallback(DNSLookupID(i, l.validationCounter), cb, status, ai); + // An error happened, we have a return code + // We can directly call the delegate with it instead + // of calling `passToDNSCallback` (which doesn't support + // a `null` result on some platforms) + if (ai is null) + cb(DNSLookupID(i, l.validationCounter), status, null); + else + passToDNSCallback(DNSLookupID(i, l.validationCounter), cb, status, ai); } else lastmax = i; } }