From 3e3c639c753b928141c9a59fe50239f8b566b346 Mon Sep 17 00:00:00 2001 From: Junliang Yan Date: Fri, 6 Nov 2015 13:46:16 -0500 Subject: [PATCH] dns: prevent undefined values in results When getaddrinfo linked-list results contain entries other than AF_INET and AF_INET6, the resulting v8::Array will contain undefined values. That's because initialization of v8::Array pre-allocates entries for all linked-list nodes, but not all of them will be in the final results. This commit ensures that the array only contains valid results. PR-URL: https://github.com/nodejs/node/pull/3696 Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis --- src/cares_wrap.cc | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index b004e67c4e8479..8f57dfe477cda4 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -922,19 +922,12 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { struct addrinfo *address; int n = 0; - // Count the number of responses. - for (address = res; address; address = address->ai_next) { - n++; - } - // Create the response array. - Local results = Array::New(env->isolate(), n); + Local results = Array::New(env->isolate()); char ip[INET6_ADDRSTRLEN]; const char *addr; - n = 0; - // Iterate over the IPv4 responses again this time creating javascript // strings for each IP and filling the results array. address = res;