Merge branch 'develop' of github.com:eclipse/paho.mqtt.c into develop

This commit is contained in:
Ian Craggs 2021-04-01 12:41:37 +01:00
commit 88ad7e5251
2 changed files with 37 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 IBM Corp.
* Copyright (c) 2009, 2021 IBM Corp. and Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
@ -569,7 +569,15 @@ void* MQTTPacket_publish(int MQTTVersion, unsigned char aHeader, char* data, siz
goto exit;
}
if (pack->header.bits.qos > 0) /* Msgid only exists for QoS 1 or 2 */
{
if (enddata - curdata < 2) /* Is there enough data for the msgid? */
{
free(pack);
pack = NULL;
goto exit;
}
pack->msgId = readInt(&curdata);
}
else
pack->msgId = 0;
if (MQTTVersion >= MQTTVERSION_5)
@ -792,7 +800,15 @@ void* MQTTPacket_ack(int MQTTVersion, unsigned char aHeader, char* data, size_t
pack->MQTTVersion = MQTTVersion;
pack->header.byte = aHeader;
if (pack->header.bits.type != DISCONNECT)
{
if (enddata - curdata < 2) /* Is there enough data for the msgid? */
{
free(pack);
pack = NULL;
goto exit;
}
pack->msgId = readInt(&curdata);
}
if (MQTTVersion >= MQTTVERSION_5)
{
MQTTProperties props = MQTTProperties_initializer;

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 IBM Corp.
* Copyright (c) 2009, 2021 IBM Corp. and Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
@ -150,17 +150,15 @@ void* MQTTPacket_connack(int MQTTVersion, unsigned char aHeader, char* data, siz
goto exit;
pack->MQTTVersion = MQTTVersion;
pack->header.byte = aHeader;
if (datalen < 2) /* enough data for connect flags and reason code? */
{
free(pack);
pack = NULL;
goto exit;
}
pack->flags.all = readChar(&curdata); /* connect flags */
pack->rc = readChar(&curdata); /* reason code */
if (MQTTVersion < MQTTVERSION_5)
{
if (datalen != 2)
{
free(pack);
pack = NULL;
}
}
else if (datalen > 2)
if (MQTTVersion >= MQTTVERSION_5 && datalen > 2)
{
MQTTProperties props = MQTTProperties_initializer;
pack->properties = props;
@ -300,6 +298,12 @@ void* MQTTPacket_suback(int MQTTVersion, unsigned char aHeader, char* data, size
goto exit;
pack->MQTTVersion = MQTTVersion;
pack->header.byte = aHeader;
if (enddata - curdata < 2) /* Is there enough data to read the msgid? */
{
free(pack);
pack = NULL;
goto exit;
}
pack->msgId = readInt(&curdata);
if (MQTTVersion >= MQTTVERSION_5)
{
@ -416,6 +420,12 @@ void* MQTTPacket_unsuback(int MQTTVersion, unsigned char aHeader, char* data, si
goto exit;
pack->MQTTVersion = MQTTVersion;
pack->header.byte = aHeader;
if (enddata - curdata < 2) /* Is there enough data? */
{
free(pack);
pack = NULL;
goto exit;
}
pack->msgId = readInt(&curdata);
pack->reasonCodes = NULL;
if (MQTTVersion >= MQTTVERSION_5)