Add a check when publishing data to be able to publish a message without data without crashing.

Signed-off-by: Marius Vikhammer <marius.vikhammer@espressif.com>

Merges https://github.com/espressif/esp-mqtt/pull/117
This commit is contained in:
Laurent Louf authored and Marius Vikhammer committed 2019-09-24 18:25:55 +08:00
1 parent 2b04d177c7
commit 2e0e93a2d3
1 file changed
+5 -2
+5 -2
View File
@@ -449,8 +449,11 @@ mqtt_message_t *mqtt_msg_publish(mqtt_connection_t *connection, const char *topi
connection->message.length = connection->buffer_length;
connection->message.fragmented_msg_total_length = data_length + connection->message.fragmented_msg_data_offset;
} else {
memcpy(connection->buffer + connection->message.length, data, data_length);
connection->message.length += data_length;
if (data != NULL)
{
memcpy(connection->buffer + connection->message.length, data, data_length);
connection->message.length += data_length;
}
connection->message.fragmented_msg_total_length = 0;
}
return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain);