Skip to content

Commit 66d045e

Browse files
committed
Check length of fqdn not srv host
1 parent c2bc931 commit 66d045e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

pymongo/asynchronous/srv_resolver.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(
9696
except Exception:
9797
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None
9898
self.__slen = len(self.__plist)
99+
self.nparts = len(self.__fqdn.split("."))
99100

100101
async def get_options(self) -> Optional[str]:
101102
from dns import resolver
@@ -138,7 +139,7 @@ async def _get_srv_response_and_hosts(
138139
# Validate hosts
139140
for node in nodes:
140141
srv_host = node[0].lower()
141-
if self.__fqdn == srv_host and len(srv_host.split(".")) < 3:
142+
if self.__fqdn == srv_host and self.nparts < 3:
142143
raise ConfigurationError(
143144
"Invalid SRV host: return address is identical to SRV hostname"
144145
)

pymongo/synchronous/srv_resolver.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(
9696
except Exception:
9797
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None
9898
self.__slen = len(self.__plist)
99+
self.nparts = len(self.__fqdn.split("."))
99100

100101
def get_options(self) -> Optional[str]:
101102
from dns import resolver
@@ -138,7 +139,7 @@ def _get_srv_response_and_hosts(
138139
# Validate hosts
139140
for node in nodes:
140141
srv_host = node[0].lower()
141-
if self.__fqdn == srv_host and len(srv_host.split(".")) < 3:
142+
if self.__fqdn == srv_host and self.nparts < 3:
142143
raise ConfigurationError(
143144
"Invalid SRV host: return address is identical to SRV hostname"
144145
)

0 commit comments

Comments
 (0)