]> git.ipfire.org Git - thirdparty/tornado.git/commit
is_valid_ip: Do not raise exceptions on too-long input. 3010/head
authorAlex Vandiver <alex@chmrr.net>
Wed, 7 Apr 2021 20:11:15 +0000 (13:11 -0700)
committerAlex Vandiver <alex@chmrr.net>
Mon, 10 May 2021 03:00:55 +0000 (17:00 -1000)
commit149159d19334fe5f7c1b553e8f6c92a8e3f04385
tree256d737e31c08c0671010b3c30df1dd0b4ba0405
parent1db5b45918da8303d2c6958ee03dbbd5dc2709e9
is_valid_ip: Do not raise exceptions on too-long input.

is_valid_ip calls `socket.getaddrinfo` with `socket.AI_NUMERICHOST` on
the potential "ip"; even though IP addresses are not hostnames and do
not use the `idna` encoding, `socket.getaddrinfo` will raise
UnicodeError if the potential "ip" is longer than 63 characters long,
the RFC-mandated max hostname length.

Catch these UnicodeErrors and return false for too-long IPs, rather
than raising an exception.
tornado/netutil.py
tornado/test/netutil_test.py