Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed a bug in socket.getfqdn()
When getfqdn called with name "::", instead of returning gethostname(), it will call gethostbyaddr("::").
This will raise an exception "socket.herror: [Errno 1] Unknown host", which will cause a 30 seconds(timeout) delay and return incorrect result.
The solution is to add a filter to the first if statement, in line 792 socket.py.
  • Loading branch information
YuriNek0 committed Dec 20, 2022
commit 77c52fc37b5670041bf2b22e3c1c3df29e6f1cfa
4 changes: 2 additions & 2 deletions Lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,11 @@ def getfqdn(name=''):

First the hostname returned by gethostbyaddr() is checked, then
possibly existing aliases. In case no FQDN is available and `name`
was given, it is returned unchanged. If `name` was empty or '0.0.0.0',
was given, it is returned unchanged. If `name` was empty, '0.0.0.0' or '::',
hostname from gethostname() is returned.
"""
name = name.strip()
if not name or name == '0.0.0.0':
if not name or name == '0.0.0.0' or name == '::':
Comment thread
YuriNek0 marked this conversation as resolved.
Outdated
name = gethostname()
try:
hostname, aliases, ipaddrs = gethostbyaddr(name)
Expand Down