Bug 1190502 - RESOLVE_DISABLE_IPV4 returns A records r=mcmanus

nsHostResolver::ThreadFunc should not override addressFamily with PR_AF_UNSPEC
for IPv6 since GetAddrInfo.cpp::GetAddrInfo() can handle PR_AF_INET6.
_GetAddrInfo_Portable does this before calling PR_GetAddrInfoByName and
creates the AddrInfo with a disableIPv4 flag if necessary.
This commit is contained in:
Valentin Gosu 2015-08-08 07:12:02 +02:00
parent e681dbf3ed
commit ab841833ea
4 changed files with 85 additions and 7 deletions

View File

@ -1403,19 +1403,14 @@ nsHostResolver::ThreadFunc(void *arg)
bool getTtl = false;
#endif
// We need to remove IPv4 records manually
// because PR_GetAddrInfoByName doesn't support PR_AF_INET6.
bool disableIPv4 = rec->af == PR_AF_INET6;
uint16_t af = disableIPv4 ? PR_AF_UNSPEC : rec->af;
nsresult status = GetAddrInfo(rec->host, af, rec->flags, rec->netInterface,
nsresult status = GetAddrInfo(rec->host, rec->af, rec->flags, rec->netInterface,
&ai, getTtl);
#if defined(RES_RETRY_ON_FAILURE)
if (NS_FAILED(status) && rs.Reset()) {
status = GetAddrInfo(rec->host, af, rec->flags, rec->netInterface, &ai,
status = GetAddrInfo(rec->host, rec->af, rec->flags, rec->netInterface, &ai,
getTtl);
}
#endif
TimeDuration elapsed = TimeStamp::Now() - startTime;
uint32_t millis = static_cast<uint32_t>(elapsed.ToMilliseconds());

View File

@ -0,0 +1,40 @@
//
// Tests that calling asyncResolve with the RESOLVE_DISABLE_IPV4 flag doesn't
// return any IPv4 addresses.
//
var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var listener = {
onLookupComplete: function(inRequest, inRecord, inStatus) {
if (inStatus != Cr.NS_OK) {
do_check_eq(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
do_test_finished();
return;
}
while (true) {
try {
var answer = inRecord.getNextAddrAsString();
// If there is an answer it should be an IPv6 address
dump(answer);
do_check_true(answer.indexOf(':') != -1);
} catch (e) {
break;
}
}
do_test_finished();
}
};
function run_test() {
do_test_pending();
try {
dns.asyncResolve("example.org", Ci.nsIDNSService.RESOLVE_DISABLE_IPV4, listener, null);
} catch (e) {
dump(e);
do_check_true(false);
do_test_finished();
}
}

View File

@ -0,0 +1,41 @@
//
// Tests that calling asyncResolve with the RESOLVE_DISABLE_IPV6 flag doesn't
// return any IPv6 addresses.
//
var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var listener = {
onLookupComplete: function(inRequest, inRecord, inStatus) {
if (inStatus != Cr.NS_OK) {
do_check_eq(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
do_test_finished();
return;
}
while (true) {
try {
var answer = inRecord.getNextAddrAsString();
// If there is an answer it should be an IPv4 address
dump(answer);
do_check_true(answer.indexOf(':') == -1);
do_check_true(answer.indexOf('.') != -1);
} catch (e) {
break;
}
}
do_test_finished();
}
};
function run_test() {
do_test_pending();
try {
dns.asyncResolve("example.com", Ci.nsIDNSService.RESOLVE_DISABLE_IPV6, listener, null);
} catch (e) {
dump(e);
do_check_true(false);
do_test_finished();
}
}

View File

@ -324,3 +324,5 @@ skip-if = os == "android"
[test_packaged_app_service.js]
[test_suspend_channel_before_connect.js]
[test_inhibit_caching.js]
[test_dns_disable_ipv4.js]
[test_dns_disable_ipv6.js]