X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmqtt.c;h=8bc412c9497213074a738ca7dfa355209c1872d1;hb=6286127470b83578c2889db546cfa32cb0fe0147;hp=cbffa67e98d411f9c1fe805c1b75f0752cee8f66;hpb=aaff848cf8b7752c7549590637f1b7702e32221e;p=collectd.git diff --git a/src/mqtt.c b/src/mqtt.c index cbffa67e..8bc412c9 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -185,9 +185,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); @@ -216,7 +217,16 @@ 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."); + sfree (vl.values); + 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) @@ -642,7 +652,7 @@ static int mqtt_config_publisher (oconfig_item_t *ci) * User "guest" * Password "secret" * Topic "collectd/#" - * + * */ static int mqtt_config_subscriber (oconfig_item_t *ci) { @@ -719,7 +729,7 @@ static int mqtt_config_subscriber (oconfig_item_t *ci) ERROR ("mqtt plugin: Unknown config option: %s", child->key); } - tmp = realloc (subscribers, sizeof (*subscribers) * subscribers_num); + tmp = realloc (subscribers, sizeof (*subscribers) * (subscribers_num + 1) ); if (tmp == NULL) { ERROR ("mqtt plugin: realloc failed.");