Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 386e0de

Browse files
committed
fix critical array overrun bug (incomingUBX->payload[] index was only checked against MAX_PAYLOAD_SIZE, but incomingUBX can also be packetAck or packetBuf which have much smaller buffers of only 2 bytes)
1 parent c914451 commit 386e0de

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,9 @@ void SFE_UBLOX_GPS::processRTCM(uint8_t incoming)
760760
//a subset of bytes within a larger packet.
761761
void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID)
762762
{
763+
size_t max_payload_size = (activePacketBuffer == SFE_UBLOX_PACKET_PACKETCFG) ? MAX_PAYLOAD_SIZE : 2;
764+
bool overrun = false;
765+
763766
//Add all incoming bytes to the rolling checksum
764767
//Stop at len+4 as this is the checksum bytes to that should not be added to the rolling checksum
765768
if (incomingUBX->counter < incomingUBX->len + 4)
@@ -931,18 +934,22 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t
931934
if ((incomingUBX->counter - 4) >= startingSpot)
932935
{
933936
//Check to see if we have room for this byte
934-
if (((incomingUBX->counter - 4) - startingSpot) < MAX_PAYLOAD_SIZE) //If counter = 208, starting spot = 200, we're good to record.
937+
if (((incomingUBX->counter - 4) - startingSpot) < max_payload_size) //If counter = 208, starting spot = 200, we're good to record.
935938
{
936939
incomingUBX->payload[incomingUBX->counter - 4 - startingSpot] = incoming; //Store this byte into payload array
937940
}
941+
else
942+
{
943+
overrun = true;
944+
}
938945
}
939946
}
940947
}
941948

942949
//Increment the counter
943950
incomingUBX->counter++;
944951

945-
if (incomingUBX->counter == MAX_PAYLOAD_SIZE)
952+
if (overrun or incomingUBX->counter == MAX_PAYLOAD_SIZE)
946953
{
947954
//Something has gone very wrong
948955
currentSentence = NONE; //Reset the sentence to being looking for a new start char

0 commit comments

Comments
 (0)