From f3e31baf04db7926e912e687a544b93c2547363e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 12 Jun 2015 00:56:52 +0100 Subject: Properly consider malformed IPv6 domains as invalid. --- slixmpp/jid.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'slixmpp/jid.py') diff --git a/slixmpp/jid.py b/slixmpp/jid.py index 1df7d1f0..8a1530c3 100644 --- a/slixmpp/jid.py +++ b/slixmpp/jid.py @@ -30,6 +30,8 @@ ILLEGAL_CHARS = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r' + \ '\x1a\x1b\x1c\x1d\x1e\x1f' + \ ' !"#$%&\'()*+,./:;<=>?@[\\]^_`{|}~\x7f' +HAVE_INET_PTON = hasattr(socket, 'inet_pton') + #: The basic regex pattern that a JID must match in order to determine #: the local, domain, and resource parts. This regex does NOT do any #: validation, which requires application of nodeprep, resourceprep, etc. @@ -199,10 +201,10 @@ def _validate_domain(domain): pass # Check if this is an IPv6 address - if not ip_addr and hasattr(socket, 'inet_pton'): + if not ip_addr and HAVE_INET_PTON and domain[0] == '[' and domain[-1] == ']': try: - socket.inet_pton(socket.AF_INET6, domain.strip('[]')) - domain = '[%s]' % domain.strip('[]') + ip = domain[1:-1] + socket.inet_pton(socket.AF_INET6, ip) ip_addr = True except (socket.error, ValueError): pass -- cgit v1.2.3