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

Payload buffer overrun fix #153

Merged
merged 2 commits into from
Nov 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/SparkFun_Ublox_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ void SFE_UBLOX_GPS::processRTCM(uint8_t incoming)
//a subset of bytes within a larger packet.
void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID)
{
size_t max_payload_size = (activePacketBuffer == SFE_UBLOX_PACKET_PACKETCFG) ? MAX_PAYLOAD_SIZE : 2;
bool overrun = false;

//Add all incoming bytes to the rolling checksum
//Stop at len+4 as this is the checksum bytes to that should not be added to the rolling checksum
if (incomingUBX->counter < incomingUBX->len + 4)
Expand Down Expand Up @@ -924,25 +927,29 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t
uint16_t startingSpot = incomingUBX->startingSpot;
if (incomingUBX->cls == UBX_CLASS_NAV && incomingUBX->id == UBX_NAV_PVT)
startingSpot = 0;
//Begin recording if counter goes past startingSpot
if ((incomingUBX->counter - 4) >= startingSpot)
// Check if this is payload data which should be ignored
if (ignoreThisPayload == false)
{
//Check to see if we have room for this byte
if (((incomingUBX->counter - 4) - startingSpot) < MAX_PAYLOAD_SIZE) //If counter = 208, starting spot = 200, we're good to record.
//Begin recording if counter goes past startingSpot
if ((incomingUBX->counter - 4) >= startingSpot)
{
// Check if this is payload data which should be ignored
if (ignoreThisPayload == false)
//Check to see if we have room for this byte
if (((incomingUBX->counter - 4) - startingSpot) < max_payload_size) //If counter = 208, starting spot = 200, we're good to record.
{
incomingUBX->payload[incomingUBX->counter - 4 - startingSpot] = incoming; //Store this byte into payload array
}
else
{
overrun = true;
}
}
}
}

//Increment the counter
incomingUBX->counter++;

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