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

Commit 94cceea

Browse files
authored
Merge pull request #153 from nelarsen/payload_overrun_fix
Payload buffer overrun fix
2 parents f6a1fe0 + 386e0de commit 94cceea

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,9 @@ void SFE_UBLOX_GPS::processRTCM(uint8_t incoming)
761761
//a subset of bytes within a larger packet.
762762
void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID)
763763
{
764+
size_t max_payload_size = (activePacketBuffer == SFE_UBLOX_PACKET_PACKETCFG) ? MAX_PAYLOAD_SIZE : 2;
765+
bool overrun = false;
766+
764767
//Add all incoming bytes to the rolling checksum
765768
//Stop at len+4 as this is the checksum bytes to that should not be added to the rolling checksum
766769
if (incomingUBX->counter < incomingUBX->len + 4)
@@ -926,25 +929,29 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t
926929
uint16_t startingSpot = incomingUBX->startingSpot;
927930
if (incomingUBX->cls == UBX_CLASS_NAV && incomingUBX->id == UBX_NAV_PVT)
928931
startingSpot = 0;
929-
//Begin recording if counter goes past startingSpot
930-
if ((incomingUBX->counter - 4) >= startingSpot)
932+
// Check if this is payload data which should be ignored
933+
if (ignoreThisPayload == false)
931934
{
932-
//Check to see if we have room for this byte
933-
if (((incomingUBX->counter - 4) - startingSpot) < MAX_PAYLOAD_SIZE) //If counter = 208, starting spot = 200, we're good to record.
935+
//Begin recording if counter goes past startingSpot
936+
if ((incomingUBX->counter - 4) >= startingSpot)
934937
{
935-
// Check if this is payload data which should be ignored
936-
if (ignoreThisPayload == false)
938+
//Check to see if we have room for this byte
939+
if (((incomingUBX->counter - 4) - startingSpot) < max_payload_size) //If counter = 208, starting spot = 200, we're good to record.
937940
{
938941
incomingUBX->payload[incomingUBX->counter - 4 - startingSpot] = incoming; //Store this byte into payload array
939942
}
943+
else
944+
{
945+
overrun = true;
946+
}
940947
}
941948
}
942949
}
943950

944951
//Increment the counter
945952
incomingUBX->counter++;
946953

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

0 commit comments

Comments
 (0)