Closed ToyboxZach closed 1 month ago
Thank you for reporting this issue, and for pointing us in the right direction; this is a bug.
Since we're inserting a null term, we shouldn't be reading the entire WS_BUFFER_SIZE
. Instead, we need to leave space for the terminator.
PS: If you're interested in fixing this bug, feel free to submit a PR, we'd be happy to review and merge it!
so the idea to fix it is to: ws->buffer = malloc(WS_BUFFER_SIZE+1);
or to check the size if the total is the same? which one should be the best one to solve the issue?
Answers checklist.
IDF version.
master
Espressif SoC revision.
esp32
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
from code
Power Supply used.
USB
What is the expected behavior?
No memory corruption
What is the actual behavior?
There is a memory corruption in this loop.
If you end up reading the full header size (my use case is if my websocket server is down, it returns static html) this ends up writing one bit past the end of the buffer
In the init functio nthere is
header_len can be up to the size of WS_BUFFER_SIZE, which is how much memory is allocated in ws->buffer
When you do ws->buffer[WS_BUFFER_SIZE] then you will corrupt some memory. In my complicated use case this ends up crashing when freeing the transport later.
Steps to reproduce.
Try to do a WS connect with a sit that doesn't return a valid header
Debug Logs.
More Information.
No response