mirror of
https://github.com/danog/dns.git
synced 2024-11-26 12:04:40 +01:00
Use ext-filter instead of inet_pton to avoid error suppression (#73)
This commit is contained in:
parent
e9ee48e269
commit
41d02a30bb
@ -42,7 +42,8 @@
|
||||
"amphp/parser": "^1",
|
||||
"amphp/uri": "^0.1",
|
||||
"amphp/windows-registry": "^0.3",
|
||||
"daverandom/libdns": "^2.0.1"
|
||||
"daverandom/libdns": "^2.0.1",
|
||||
"ext-filter": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"amphp/phpunit-util": "^1",
|
||||
|
@ -89,23 +89,28 @@ final class BasicResolver implements Resolver {
|
||||
yield $this->reloadConfig();
|
||||
}
|
||||
|
||||
$inAddr = @\inet_pton($name);
|
||||
|
||||
if ($inAddr !== false) {
|
||||
// It's already a valid IP, don't query, immediately return
|
||||
if ($typeRestriction) {
|
||||
if ($typeRestriction === Record::A && isset($inAddr[4])) {
|
||||
switch ($typeRestriction) {
|
||||
case Record::A:
|
||||
if (filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||
return [new Record($name, Record::A, null)];
|
||||
} elseif (filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
throw new ResolutionException("Got an IPv6 address, but type is restricted to IPv4");
|
||||
}
|
||||
|
||||
if ($typeRestriction === Record::AAAA && !isset($inAddr[4])) {
|
||||
break;
|
||||
case Record::AAAA:
|
||||
if (filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
return [new Record($name, Record::AAAA, null)];
|
||||
} elseif (filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||
throw new ResolutionException("Got an IPv4 address, but type is restricted to IPv6");
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
new Record($name, isset($inAddr[4]) ? Record::AAAA : Record::A, null),
|
||||
];
|
||||
break;
|
||||
default:
|
||||
if (filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||
return [new Record($name, Record::A, null)];
|
||||
} elseif (filter_var($name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
return [new Record($name, Record::AAAA, null)];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$name = normalizeDnsName($name);
|
||||
|
Loading…
Reference in New Issue
Block a user