Skip to content

Commit 3e3c639

Browse files
Junliang Yanrvagg
Junliang Yan
authored andcommitted
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: #3696 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent a14d164 commit 3e3c639

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

src/cares_wrap.cc

+1-8
Original file line numberDiff line numberDiff line change
@@ -922,19 +922,12 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
922922
struct addrinfo *address;
923923
int n = 0;
924924

925-
// Count the number of responses.
926-
for (address = res; address; address = address->ai_next) {
927-
n++;
928-
}
929-
930925
// Create the response array.
931-
Local<Array> results = Array::New(env->isolate(), n);
926+
Local<Array> results = Array::New(env->isolate());
932927

933928
char ip[INET6_ADDRSTRLEN];
934929
const char *addr;
935930

936-
n = 0;
937-
938931
// Iterate over the IPv4 responses again this time creating javascript
939932
// strings for each IP and filling the results array.
940933
address = res;

0 commit comments

Comments
 (0)