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
This commit is contained in:
Kevin Easton
2012-05-15 13:29:32 +00:00
parent 9ec4f49540
commit ba365bfd54
2 changed files with 4 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
[Changes 1.2c01] [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 * Apply patch from snadge defining BIND_4_COMPAT on OpenBSD, to allow
/nslookup to build. (caf) /nslookup to build. (caf)

View File

@@ -639,10 +639,11 @@ int lame_resolv (const char *hostname, struct sockaddr_foobar *buffer)
{ {
#ifdef IPV6 #ifdef IPV6
struct addrinfo *res; struct addrinfo *res;
if (getaddrinfo(hostname, NULL, NULL, &res) && res) if (getaddrinfo(hostname, NULL, NULL, &res) || !res)
return -1; return -1;
memmove(buffer, res->ai_addr, res->ai_addrlen); memmove(buffer, res->ai_addr, res->ai_addrlen);
freeaddrinfo(res);
return 0; return 0;
#else #else
struct hostent *hp; struct hostent *hp;