Commit ed1d61c9 authored by juga's avatar juga
Browse files

Merge branch 'ticket28141'

parents 1defb776 8787741b
......@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Update python minimal version in setup (#28043)
- Catch unhandled exception when we fail to resolve a domain name (#28141)
### Changed
......
......@@ -68,8 +68,16 @@ def touch_file(fname, times=None):
def resolve(hostname, ipv4_only=False, ipv6_only=False):
assert not (ipv4_only and ipv6_only)
results = []
try:
results = socket.getaddrinfo(hostname, 0)
except socket.gaierror:
log.warn(
'Unable to resolve %s hostname. Returning empty list of addresses',
hostname)
return []
ret = set()
for result in socket.getaddrinfo(hostname, 0):
for result in results:
fam, _, _, _, addr = result
if fam == socket.AddressFamily.AF_INET6 and not ipv4_only:
ret.add(addr[0])
......
......@@ -120,7 +120,10 @@ class Relay:
#
# Also, only use the first ipv4/6 we get even if there is more than
# one.
host = resolve(host)[0]
results = resolve(host)
if not len(results):
return False
host = results[0]
assert is_valid_ipv4_address(host) or is_valid_ipv6_address(host)
return self.exit_policy.can_exit_to(host, port)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment