drop connection on response longer than 100 bytes that can't' be decoded
This commit is contained in:
parent
871e6e6f64
commit
b65570fb16
1 changed files with 7 additions and 2 deletions
|
@ -45,19 +45,23 @@ class ReflectorServer(Protocol):
|
|||
extra_data = None
|
||||
response = None
|
||||
curr_pos = 0
|
||||
size_of_message = len(response_msg)
|
||||
while 1:
|
||||
next_close_paren = response_msg.find('}', curr_pos)
|
||||
if next_close_paren != -1:
|
||||
curr_pos = next_close_paren + 1
|
||||
try:
|
||||
response = json.loads(response_msg[:curr_pos])
|
||||
failed_to_decode = False
|
||||
except ValueError:
|
||||
pass
|
||||
failed_to_decode = True
|
||||
else:
|
||||
extra_data = response_msg[curr_pos:]
|
||||
break
|
||||
else:
|
||||
break
|
||||
if size_of_message > 100 and failed_to_decode:
|
||||
raise Exception("error decoding response")
|
||||
return response, extra_data
|
||||
|
||||
def handle_request(self, request_dict):
|
||||
|
@ -121,7 +125,8 @@ class ReflectorServer(Protocol):
|
|||
self.transport.write(json.dumps(response_dict))
|
||||
|
||||
def handle_error(self, err):
|
||||
pass
|
||||
log.error(err.getTraceback())
|
||||
self.transport.loseConnection()
|
||||
|
||||
|
||||
class ReflectorServerFactory(ServerFactory):
|
||||
|
|
Loading…
Reference in a new issue