From 02acfb1242d126e17a295ff8078ef9a73201c7ca Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 21 Jul 2016 10:38:37 +1200 Subject: Fix netlib.utils.is_valid_host - Don't crash when passed an empty string. This translated into an actual core crash, discovered while fuzzing with afl. - Taking a slice of length one out of bytes returns an integer, so the check for trailing period in this function never worked on Python3. - Add unit tests. --- netlib/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'netlib/utils.py') diff --git a/netlib/utils.py b/netlib/utils.py index 9eebf22c..0deb7c82 100644 --- a/netlib/utils.py +++ b/netlib/utils.py @@ -82,7 +82,7 @@ _label_valid = re.compile(b"(?!-)[A-Z\d-]{1,63}(? bool """ - Checks if a hostname is valid. + Checks if a hostname is valid. """ try: host.decode("idna") @@ -90,7 +90,7 @@ def is_valid_host(host): return False if len(host) > 255: return False - if host[-1] == b".": + if host and host[-1:] == b".": host = host[:-1] return all(_label_valid.match(x) for x in host.split(b".")) -- cgit v1.2.3