8000 gh-100374: Fixed a bug in socket.getfqdn() by MTAwsl · Pull Request #100375 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-100374: Fixed a bug in socket.getfqdn() #100375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 21, 2022
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
MTAwsl 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 == '::':
name = gethostname()
try:
hostname, aliases, ipaddrs = gethostbyaddr(name)
Expand Down
0