From 2b04d177c76728a5a389a08a4a9a78238549a13a Mon Sep 17 00:00:00 2001 From: Laurent Louf Date: Fri, 3 May 2019 12:05:29 +0200 Subject: [PATCH] Add a check when publishing data to verify that if some data length is set, data pointer cannot be NULL, in which case an error is returned. Signed-off-by: Marius Vikhammer --- lib/mqtt_msg.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mqtt_msg.c b/lib/mqtt_msg.c index 05ffa19..1d67119 100644 --- a/lib/mqtt_msg.c +++ b/lib/mqtt_msg.c @@ -430,6 +430,10 @@ mqtt_message_t *mqtt_msg_publish(mqtt_connection_t *connection, const char *topi return fail_message(connection); } + if (data == NULL && data_length > 0) { + return fail_message(connection); + } + if (qos > 0) { if ((*message_id = append_message_id(connection, 0)) == 0) { return fail_message(connection);