Skip to content

Commit

Permalink
Fix potential overwrites #242
Browse files Browse the repository at this point in the history
  • Loading branch information
icraggs committed Jun 6, 2023
1 parent 29ab2aa commit dc8d837
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions MQTTPacket/src/MQTTSubscribeServer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014 IBM Corp.
* Copyright (c) 2014, 2023 IBM Corp., Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -38,7 +38,7 @@ int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, int
MQTTHeader header = {0};
unsigned char* curdata = buf;
unsigned char* enddata = NULL;
int rc = -1;
int rc = MQTTPACKET_READ_ERROR;
int mylen = 0;

FUNC_ENTRY;
Expand All @@ -47,14 +47,20 @@ int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, int
goto exit;
*dup = header.bits.dup;

curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
rc = MQTTPacket_decodeBuf(curdata, &mylen); /* read remaining length */
if (rc <= 0)
goto exit;
curdata += rc;
rc = MQTTPACKET_READ_ERROR;
enddata = curdata + mylen;

*packetid = readInt(&curdata);

*count = 0;
while (curdata < enddata)
{
if (*count == maxcount)
goto exit;
if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata))
goto exit;
if (curdata >= enddata) /* do we have enough data to read the req_qos version byte? */
Expand Down

0 comments on commit dc8d837

Please sign in to comment.