detd icon indicating copy to clipboard operation
detd copied to clipboard

Null bytes in protobuf messages sent via unix datagram socket

Open koalo opened this issue 2 years ago • 3 comments

Hi, I just noticed that when the service sends a StreamQosResponse with ok = False, an empty packet is received on receiver side. The reason for that is that protobuf messages are allowed to contain null bytes (and a False boolean is encoded as null byte \0). Unfortunately, that is also the terminator of a datagram. In the current implementation that probably got unnoticed, because if ok = False the subsequent fields are ignored anyway. However, I still think we should avoid sending raw protobuf messages via unix datagram sockets.

I am happy to provide a fix, but since there are many different options to solve this, I would appreciate your opinion on this topic:

  1. We could further encode the protobuf message to prevent null bytes (e.g. as Base64).
  2. We could avoid using datagram sockets and use stream sockets instead. We would then need a method for separating the messages in the stream again.
  3. We completely avoid protobuf and use another IPC method. One option that you already mentioned in the README would be to replace it by DBus.

What do you think?

koalo avatar Feb 24 '23 07:02 koalo