Tinkerforge/generators

Crash in ip connection on invalid packet

Opened this issue · 1 comments

I am not entirely sure, if this is the correct repo for this report. I do have a problem with some of the bricks in a noisy environment. Noisy in this context means, that every once in a while the MCU on the Master Brick seems to send garbarge and if the ip connection receives this garbarge, its thread crashes.

I am using the Python implementation and I have the following taceback:

Exception in thread Brickd-Receiver:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/sensorDaemon/sensors/tinkerforge/ip_connection.py", line 1052, in receive_loop
    self.handle_response(packet)
  File "/sensorDaemon/sensors/tinkerforge/ip_connection.py", line 1355, in handle_response
    function_id = get_function_id_from_data(packet)
  File "/sensorDaemon/sensors/tinkerforge/ip_connection.py", line 41, in get_function_id_from_data
    return struct.unpack('<B', data[5:6])[0]
struct.error: unpack requires a buffer of 1 bytes 

It would be nice to see some kind of exception handling, when unpacking structs coming from untrustworthy sources.

This is a known problem in all the bindings. It's on the TODO list to be fixed. The fix will be to verify the incoming data in a more strict way before interpreting it. If garbage is received the IP Connection will disconnect and auto-reconnect (if enabled) to synchronize again.