mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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 <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
1 parent
301e166d20
commit
e1cefda70f
1 file changed
+1
-8
+1
-8
@@ -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<Array> results = Array::New(env->isolate(), n);
|
||||
Local<Array> 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;
|
||||
|
||||
Reference in new issue
Block a user