From b1d65a194afef0d2c4dba09b815eec1976666673 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 14 Apr 2012 16:26:24 -0700 Subject: [PATCH] Fix memory corruption with DNS lookups. Thanks @Mystler for finding and reporting this, and thanks @Hoikas for investigating and confirming the fix. --- .../Private/Win32/pnAceW32Dns.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp index 3aa557b3..948727ab 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp @@ -88,9 +88,6 @@ static unsigned s_nextLookupCancelId = 1; //=========================================================================== static void LookupProcess (Lookup * lookup, unsigned error) { - unsigned count = 0; - plNetAddress* addrs = nil; - if (error) return; @@ -104,20 +101,14 @@ static void LookupProcess (Lookup * lookup, unsigned error) { in_addr const * const * const inAddr = (in_addr **) host.h_addr_list; - // count the number of addresses - while (inAddr[count]) - ++count; - // allocate a buffer large enough to hold all the addresses - addrs = new plNetAddress[count]; + size_t count = arrsize(inAddr); + plNetAddress* addrs = new plNetAddress[count]; // fill in address data - const uint16_t port = htons((uint16_t) lookup->port); - for (unsigned i = 0; i < count; ++i) { - sockaddr_in * inetaddr = (sockaddr_in *) &addrs[i]; - inetaddr->sin_family = AF_INET; - inetaddr->sin_addr = *inAddr[i]; - inetaddr->sin_port = port; + for (size_t i = 0; i < count; ++i) { + addrs[i].SetHost(inAddr[i]->S_un.S_addr); + addrs[i].SetPort(lookup->port); } if (host.h_name && host.h_name[0])