me-no-dev / ESPAsyncTCP

Async TCP Library for ESP8266
GNU Lesser General Public License v3.0
758 stars 394 forks source link

data in handleData() has trash on it and can crash the esp8266 when start with "S" #173

Closed stdevPavelmc closed 3 years ago

stdevPavelmc commented 3 years ago

NodemMCU 1.0 Platformio latest version Server example sketch

The data argument has trash on it and some times crash the whole sketch on data reception, example snipet:

static void handleData(void *arg, AsyncClient *client, void *data, size_t len)
{
    Serial.write((uint8_t *)data, strlen(data));
    Serial.println(len);

    // reply to client
   // ...
}

Serial output is as this: (sent data is just "S\n")

 new client has been connected to server, ip: 10.42.1.2S
␅�␄␂��␁�␂A␁2

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (9):
epc1=0x40105ef0 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000003 depc=0x00000000

>>>stack>>>

ctx: sys
sp: 3fffeb70 end: 3fffffb0 offset: 0190
3fffed00:  3ffe8f6a 3fffed4f 3ffef408 00000002  
3fffed10:  40106121 00f3a536 3ffef5b4 00000000  
3fffed20:  3ffeed80 3ffef5b4 3ffef408 4020b4a4  
3fffed30:  00000000 00eee082 4020e524 000003e8 
[...]

The "garbage" is random and some times there is no garbage, I have used memcpy and len to cut the data but some times with some characters (specially the S one) it's prone to crash.

Data is sent like this (Linux)

# echo "S" | nc ip port -w 1
stdevPavelmc commented 3 years ago

Forget it, I managed to get the data cleaned, and triaged the crash on mi side of the code.