RAKWireless / RAK5205-WisTrio-LoRa

RAK5205-WisTrio-LoRa :GPS ,BME680,LIS3DH,LoRaWAN1.0.2,ARM Cortex-M3 STM32L1
9 stars 6 forks source link

Potential buffer overflow in NmeaString[] within gps-board.c #7

Open afremont opened 5 years ago

afremont commented 5 years ago

In module /board/RAK811/gps-board.c the array NmeaString is defined as 512 bytes, however when parsing through the incoming data in function GpsMcuIrqNotify(), the bounds check is for 1024 bytes. Perhaps it is never actually overflowing as long as '$' and '\n' is always spotted by the function, however there exists the possibility that an unusually long message might not be properly truncated by the code and would allow the function to destroy memory contents beyond the defined size of the buffer.

/*
 * \brief Buffer holding the  raw data received from the gps
 */
uint8_t NmeaString[512];

void GpsMcuIrqNotify( UartNotifyId_t id )
{
    uint8_t data;

    if( id == UART_NOTIFY_RX )
    {
        if( UartMcuGetChar( &GpsUart, &data ) == 0 )
        {
            if( ( data == '$' ) || ( NmeaStringSize >= 1024 ) )
            {
                NmeaStringSize = 0;
            }

            NmeaString[NmeaStringSize++] = ( int8_t )data;
            if( data == '\n' )
            {
                NmeaString[NmeaStringSize++] = '\0';

                GpsParseGpsData( ( int8_t* )NmeaString, NmeaStringSize );
#ifdef GPS_PPS
                UartMcuDeInit( &GpsUart );
#endif
                BlockLowPowerDuringTask ( false );
            }
        }

    }
}