Skip to content

Commit 8a83f4f

Browse files
committed
account for potentially false return value of dns_get_record
1 parent 01411f8 commit 8a83f4f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Common/DNSAddressResolver.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ public function getAddresses(string $host): iterable
3838
yield $host;
3939

4040
try {
41-
/** @var list<array{ip?: string|null}> $records */
41+
/** @var list<array{ip?: string|null}>|false $records */
4242
$records = dns_get_record($host, DNS_A | DNS_AAAA);
4343
} catch (Throwable) {
4444
$records = []; // Failed DNS queries should not halt execution
4545
}
4646

47+
if ($records === false) {
48+
$records = [];
49+
}
50+
4751
if (count($records) === 0) {
4852
yield from $this->tryReverseLookup($host);
4953
} else {
@@ -59,12 +63,16 @@ public function getAddresses(string $host): iterable
5963
private function tryReverseLookup(string $host): iterable
6064
{
6165
try {
62-
/** @var list<array{target?: string|null}> $records */
66+
/** @var list<array{target?: string|null}>|false $records */
6367
$records = dns_get_record($host.'.in-addr.arpa');
6468
} catch (Throwable) {
6569
$records = []; // Failed DNS queries should not halt execution
6670
}
6771

72+
if ($records === false) {
73+
$records = [];
74+
}
75+
6876
if (count($records) !== 0) {
6977
$records = array_map(static fn (array $x) => $x['target'] ?? '', $records);
7078
$records = array_filter($records, static fn (string $x) => $x !== '');

0 commit comments

Comments
 (0)