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.
This commit is contained in:
Geod24 2020-07-29 12:52:42 +09:00 committed by Mathias LANG
parent 9e94195bd4
commit 862b5d470c
2 changed files with 9 additions and 2 deletions

View file

@ -1,6 +1,6 @@
project('eventcore', 'd',
meson_version: '>=0.50',
version: '0.9.6'
version: '0.9.7'
)
project_soversion = '0'

View file

@ -180,6 +180,13 @@ final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriver
l.done = false;
if (i == m_maxHandle) m_maxHandle = lastmax;
m_events.loop.m_waiterCount--;
// 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;
}