]> git.ipfire.org Git - thirdparty/collectd.git/commit
MQTT: fix off-by-one error in published message length (#4005)
authorLeonard Göhrs <leonard@goehrs.eu>
Wed, 1 Jun 2022 06:04:28 +0000 (08:04 +0200)
committerGitHub <noreply@github.com>
Wed, 1 Jun 2022 06:04:28 +0000 (08:04 +0200)
commitcecc91f1eec7f473acd19c49f256297cfb56003c
tree9bb7290e9f02b04c573b1d5c4ceb752669b6a8a2
parentab869e58c1873036efd3c687823f070a3a07e6a5
MQTT: fix off-by-one error in published message length (#4005)

The mqtt plugin publishes messages including the trailing '\0'-Byte,
as can be verified using e.g. the mosquitto_sub command with a HEX message
formatter:

  $ mosquitto_sub -t "#" -F "%t: %X"
  metrics/loragw1/users/users: 313635323334303737392E3938353A3000
                                                               ^^
While the the MQTT PUBLISH payload is, according to the specification,
application specific and most (C-Based) consumers will not notice the trailing
'\0'-Byte, it is rather uncommon to publish messages like this.

We stumbled upon this error while using Telegraf to ingest metrics via MQTT,
as it is Go-Based and does not use '\0'-terminated strings, leading to issues
parsing these strings into numbers.

Fix the off-by-one error by using the result of strlen() as-is.

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
src/mqtt.c