Steven-GH / Xsens_MTi_SPI

This library demonstrates the basics of communicating with Xsens MTi 1-series devices through SPI.
MIT License
5 stars 0 forks source link

Buffer Overflow #1

Open BHO-navvis opened 1 month ago

BHO-navvis commented 1 month ago

https://github.com/Steven-GH/Xsens_MTi_SPI/blob/37564ccf9686aee4f361c0f6936bb0d70b9fe3c9/MTi.cpp#L113

BHO-navvis commented 1 month ago

`void MTi::sendMessage(uint8_t message, uint8_t numBytes) { uint8_t messageWithChecksum = new uint8_t[numBytes + 1];

// copy and calulate checksum uint8_t checksum = 0x01; for (int i = 0; i < numBytes; i++) { messageWithChecksum[i] = message[i]; checksum -= message[i]; }

// Add the checksum at the end of the Xbus message messageWithChecksum[numBytes] = checksum;

uint8_t buffer[] = {XSENS_CONTROL_PIPE, 0xFF, 0xFF, 0xFF};

SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3)); digitalWrite(nCS, LOW); SPI.transfer(buffer, sizeof(buffer)); SPI.transfer(messageWithChecksum, numBytes + 1); digitalWrite(nCS, HIGH); SPI.endTransaction(); // Speicher freigeben delete[] messageWithChecksum; }`