Skip to content

Commit

Permalink
Protect _settings[] array from accesses beyond end
Browse files Browse the repository at this point in the history
_settings[] array is accessed beyond the end of the array if BOARD_NR_SPI is defined as 1 on for example the HyTiny board.
  • Loading branch information
mitchmitchell authored Feb 8, 2019
1 parent e69cf8f commit e2f2937
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions STM32F1/libraries/SPI/src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,20 @@ SPIClass::SPIClass(uint32 spi_num)

// Init things specific to each SPI device
// clock divider setup is a bit of hack, and needs to be improved at a later date.
#if BOARD_NR_SPI >= 1
_settings[0].spi_d = SPI1;
_settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
_settings[0].spiDmaDev = DMA1;
_settings[0].spiTxDmaChannel = DMA_CH3;
_settings[0].spiRxDmaChannel = DMA_CH2;
#endif
#if BOARD_NR_SPI >= 2
_settings[1].spi_d = SPI2;
_settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
_settings[1].spiDmaDev = DMA1;
_settings[1].spiTxDmaChannel = DMA_CH5;
_settings[1].spiRxDmaChannel = DMA_CH4;
#endif
#if BOARD_NR_SPI >= 3
_settings[2].spi_d = SPI3;
_settings[2].clockDivider = determine_baud_rate(_settings[2].spi_d, _settings[2].clock);
Expand Down

0 comments on commit e2f2937

Please sign in to comment.