Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ def getfqdn(name=''):
"""
name = name.strip()
if not name or name in ('0.0.0.0', '::'):
name = gethostname()
return gethostname()
try:
hostname, aliases, ipaddrs = gethostbyaddr(name)
except error:
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,17 @@ def test_sethostname(self):
finally:
socket.sethostname(oldhn)

def test_getfqdn_undefined_address(self):
for addr in ('', '0.0.0.0', '::'):
with self.subTest(addr=addr):
called = []
with mock.patch.object(
socket, 'gethostbyaddr',
side_effect=lambda addr: called.append(addr) or ("", [], [])
):
socket.getfqdn(addr)
self.assertFalse(called, f"gethostbyaddr was called for undefined address {addr!r}")

@unittest.skipUnless(hasattr(socket, 'if_nameindex'),
'socket.if_nameindex() not available.')
@support.skip_android_selinux('if_nameindex')
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,7 @@ Daniel Stutzbach
Andreas Stührk
Colin Su
Pal Subbiah
Ilari Suhonen
Michael J. Sullivan
Nathan Sullivan
Mark Summerfield
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``getfqdn()`` attempting to resolve the computer's own hostname, instead
of returning it as-is.
Loading