Try to prevent transwhat from crashing on malformed protobuf
This commit is contained in:
parent
7f1c9cd0db
commit
f4e85f7689
|
@ -4,6 +4,7 @@ import struct
|
|||
import sys
|
||||
import os
|
||||
|
||||
import logging
|
||||
import google.protobuf
|
||||
|
||||
def WRAP(MESSAGE, TYPE):
|
||||
|
@ -24,6 +25,7 @@ class SpectrumBackend:
|
|||
self.m_pingReceived = False
|
||||
self.m_data = ""
|
||||
self.m_init_res = 0
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
|
||||
def handleMessage(self, user, legacyName, msg, nickname = "", xhtml = "", timestamp = ""):
|
||||
m = protocol_pb2.ConversationMessage()
|
||||
|
@ -349,8 +351,15 @@ class SpectrumBackend:
|
|||
|
||||
|
||||
wrapper = protocol_pb2.WrapperMessage()
|
||||
if (wrapper.ParseFromString(self.m_data[4:]) == False):
|
||||
try:
|
||||
parseFromString = wrapper.ParseFromString(self.m_data[4:])
|
||||
except:
|
||||
parseFromString = True
|
||||
self.logger.error("Parse from String exception")
|
||||
|
||||
if parseFromString == False:
|
||||
self.m_data = self.m_data[expected_size+4:]
|
||||
self.logger.error("Parse from String exception")
|
||||
return
|
||||
|
||||
self.m_data = self.m_data[4+expected_size:]
|
||||
|
|
|
@ -458,7 +458,7 @@ class Session(YowsupApp):
|
|||
else:
|
||||
room = sender
|
||||
try:
|
||||
group = self.groups[room]
|
||||
group = self.groups[self._lengthenGroupId(room)]
|
||||
self.logger.info("Group Message from %s to %s Groups: %s",
|
||||
group.nick , group , self.groups)
|
||||
self.backend.handleMessage(
|
||||
|
|
Loading…
Reference in a new issue