Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer overflow when receiving too much data #15

Open
ArminBmrt opened this issue Jan 28, 2020 · 5 comments
Open

Buffer overflow when receiving too much data #15

ArminBmrt opened this issue Jan 28, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@ArminBmrt
Copy link

Hi,

there is a bufffer overflow when the serialPort receives too much data.

I have a esp32 connected to a vesc75/300. Sometimes the vesc sends too much data (unknown cause still working on this). The function int VescUart::receiveUartMessage(uint8_t * payloadReceived) has a buffer overflow which results in the esp32 crashing.

The problem is that the variable counter is checked after incrementing and writing of data.

if (counter >= sizeof(messageReceived)) {

When the counter is too large a break is executed. This will break only the second while loop (line 36) but not the first timeout while loop (line 34). So when counter has overflown line 38 still gets executed.

I think the check on counter on line 64 should be moved before anything is written

@vicgwee
Copy link

vicgwee commented Aug 18, 2020

Might be a bit late, but you can try increasing the RX receive buffer on your esp32?

@ArminBmrt
Copy link
Author

Yes it is a bit late :) but thanks

The buffer flow still exists even if you would increase the RX receive buffer. Problem is the that the size check is inside the second while loop and when the size is too large you break from it. This still keeps you in the first while loop which will happily increment the out of bound counter and write data to it.

I have moved on to a different library which now works (I still had to heavily modify the code to make it robust).

@andrespineda
Copy link

Hi,
You mentioned that you have moved on to a different library. may I ask which library you are now using? Trying to find the best library to start with to save some time.
Thanks in advance.

@ArminBmrt
Copy link
Author

@andrespineda I used https://github.com/gianmarcov/arduino_vesc but I have modified a lot. Since I did not care about being backwards compatible I am not going to release it.

Main issues were the multiple uart ports for the esp32 and also the large stack memory allocation when receiving data. The large data allocation gave unreliable results when receiving. This might not be a problem if you only use a single vesc

@andrespineda
Copy link

andrespineda commented Sep 7, 2020 via email

@SolidGeek SolidGeek added the bug Something isn't working label Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants