From ba365bfd5486525a2071d5b5369038990a354574 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Tue, 15 May 2012 13:29:32 +0000 Subject: [PATCH] Fix logic error that can result in a potential crash (when getaddrinfo() fails and res happened to be NULL). Also add missing freeaddrinfo() call. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@188 13b04d17-f746-0410-82c6-800466cd88b0 --- Changelog | 2 ++ source/network.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index b39e4ce..59d2129 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,7 @@ [Changes 1.2c01] +* Fix leak and potential crash in lame_resolv() using IPv6. (caf, snadge) + * Apply patch from snadge defining BIND_4_COMPAT on OpenBSD, to allow /nslookup to build. (caf) diff --git a/source/network.c b/source/network.c index 748d69f..d2666b3 100644 --- a/source/network.c +++ b/source/network.c @@ -639,10 +639,11 @@ int lame_resolv (const char *hostname, struct sockaddr_foobar *buffer) { #ifdef IPV6 struct addrinfo *res; - if (getaddrinfo(hostname, NULL, NULL, &res) && res) + if (getaddrinfo(hostname, NULL, NULL, &res) || !res) return -1; memmove(buffer, res->ai_addr, res->ai_addrlen); + freeaddrinfo(res); return 0; #else struct hostent *hp;