server: Handle malformed server responses.

This commit is contained in:
Damir Jelić 2018-07-24 11:05:29 +02:00
parent 4b67dc015b
commit 32df9230ea
2 changed files with 15 additions and 3 deletions

View file

@ -35,7 +35,7 @@ import logbook
from logbook import Logger, StderrHandler, StreamHandler
import nio
from nio import TransportType
from nio import TransportType, RemoteTransportError
from matrix.colors import Formatted
from matrix.utf import utf8_decode
@ -296,7 +296,11 @@ def receive_cb(server_name, file_descriptor):
server.disconnect()
break
server.client.receive(data)
try:
server.client.receive(data)
except RemoteTransportError as e:
server.error(str(e))
server.disconnect()
response = server.client.next_response()

View file

@ -30,7 +30,7 @@ from matrix.plugin_options import Option, DebugType
from matrix.utils import (key_from_value, prnt_debug, server_buffer_prnt,
create_server_buffer)
from matrix.utf import utf8_decode
from matrix.globals import W, SERVERS
from matrix.globals import W, SERVERS, SCRIPT_NAME
from .buffer import RoomBuffer, OwnMessage, OwnAction
try:
@ -279,6 +279,14 @@ class MatrixServer:
# type: (MatrixServer) -> None
self.send_buffer = b""
def error(self, message):
buf = ""
if self.server_buffer:
buf = self.server_buffer
msg = "{prefix}{}: {}".format(SCRIPT_NAME, message)
W.prnt(buf, msg)
def send(self, data):
# type: (bytes) -> bool
self.try_send(data)