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