diff options
author | Jordan <me@jordan.im> | 2022-03-29 09:04:18 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2022-03-29 09:04:18 -0700 |
commit | 6b2a8b55068f2621c6a689504035f329801982e1 (patch) | |
tree | 30f57a68f0d360970e06f1c8bdc6bd0c1f55afaf | |
parent | b9a6d383c24ad8a0a2accf636eee7482e3e1a0de (diff) | |
download | asn-6b2a8b55068f2621c6a689504035f329801982e1.tar.gz asn-6b2a8b55068f2621c6a689504035f329801982e1.zip |
asn: catch unicode decode errors; bots make erroneous queries
-rwxr-xr-x | asn.py | 24 | ||||
m--------- | location-database | 0 |
2 files changed, 14 insertions, 10 deletions
@@ -36,18 +36,22 @@ class Listener: if not recv_data: conn.close() - recv_data = str(recv_data, 'utf-8').strip() - log.info(f'{addr[0]} {recv_data}') - - announcements = self._get_announcements(recv_data) - if not announcements: - announcements = 'no valid hostname or IP discovered' + try: + recv_data = str(recv_data, 'utf-8').strip() + except UnicodeDecodeError: + resp = 'could not decode query to utf-8' else: - announcements = self._pretty(announcements) + log.info(f'{addr[0]} {recv_data}') - conn.sendall(bytes(announcements, 'utf-8')) - conn.shutdown(socket.SHUT_RDWR) - conn.close() + resp = self._get_announcements(recv_data) + if not resp: + resp = 'no valid hostname or IP discovered' + else: + resp = self._pretty(resp) + finally: + conn.sendall(bytes(resp, 'utf-8')) + conn.shutdown(socket.SHUT_RDWR) + conn.close() def _get_announcements(self, recv): db = DB() diff --git a/location-database b/location-database -Subproject f57880612aff8d8454a5472fb04f8bc31f4fdae +Subproject 7ad544905562799b98ae99b3971d6db770ba0b4 |