From: Nicholas Humfrey Date: Thu, 26 Nov 2015 20:29:30 +0000 (+0000) Subject: Allow MQTT payloads without NULL string termination X-Git-Tag: collectd-5.6.0~577^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=42ac121bd1a39af34db4e187967756c631b606c5;p=collectd.git Allow MQTT payloads without NULL string termination --- diff --git a/src/mqtt.c b/src/mqtt.c index 1b71d423..2eb11520 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -176,9 +176,10 @@ static void on_message ( char *payload; int status; - if ((msg->payloadlen <= 0) - || (((uint8_t *) msg->payload)[msg->payloadlen - 1] != 0)) + if (msg->payloadlen <= 0) { + DEBUG ("mqtt plugin: message has empty payload"); return; + } topic = strdup (msg->topic); name = strip_prefix (topic); @@ -207,7 +208,15 @@ static void on_message ( } vl.values_len = ds->ds_num; - payload = strdup ((void *) msg->payload); + payload = malloc (msg->payloadlen+1); + if (payload == NULL) + { + ERROR ("mqtt plugin: malloc for payload buffer failed."); + return; + } + memmove (payload, msg->payload, msg->payloadlen); + payload[msg->payloadlen] = 0; + DEBUG ("mqtt plugin: payload = \"%s\"", payload); status = parse_values (payload, &vl, ds); if (status != 0)