Messages with NUL character get truncated

Bug #1247559 reported by Wolfgang Nagele
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mosquitto
Fix Released
Undecided
Unassigned

Bug Description

When sending in a message that contains \0 (NUL) anywhere in the payload it seems that the message is truncated at that very position and the rest of the payload is not delivered.

Here is an example:

We are sending in the message "test\0\0\0".
$ hexdump in
0000000 74 65 73 74 00 00 00
0000007

As expected the message has the four ASCII characters followed by three NUL control characters.

The message received is only "test".
$ hexdump out
0000000 74 65 73 74 0a
0000005

Ignore the 0a here as this is the newline that was added by mosquitto_sub which is fine.

Revision history for this message
Roger Light (roger.light) wrote :

Could you clarify how you are sending the message, i.e. what client?

Revision history for this message
Wolfgang Nagele (mail-wnagele) wrote :

Looks like the bug is in mosquitto_sub. It works fine if I use the Python module or Eclipse Paho to read the payload. I currently publish using Eclipse Paho and mosquitto_pub.

Revision history for this message
Wolfgang Nagele (mail-wnagele) wrote :

Had some time to look into the code around this and it's no surprise. mosquitto_sub expects strings in the payload only as it prints them out using printf (https://bitbucket.org/oojah/mosquitto/src/9312f0265f45fb5f7a2cb5d92d7b70e921053a98/client/sub_client.c#cl-70). This is also why control characters such as \0 cause issues.

Not sure if this is something that should/could be fixed or if mosquitto_sub simply should not be used for binary payloads?

Revision history for this message
Wolfgang Nagele (mail-wnagele) wrote :

Attached is a patch that uses fwrite to support binary payloads.

Changed in mosquitto:
milestone: none → 1.3
status: New → Fix Committed
Changed in mosquitto:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.