Skip to content

Commit

Permalink
Websockets - Avoids trying to use an empty buffer
Browse files Browse the repository at this point in the history
  Sometimes, in a SSL secure connection, the receiveCallback is called with
an empty buffer and len == 0. At those times, the websocket client gets
confused.

  At connection time, it may not receive the Upgrade answer and disconnect.
At all other times, it would try to accumulate the payload until it exaust
all memory and fails.
  • Loading branch information
Fernando Governatore committed Oct 14, 2016
1 parent 880bd98 commit c7f8c3b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/websocket/websocketclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) {
os_timer_disarm(&ws->timeoutTimer); // reset ping check
os_timer_arm(&ws->timeoutTimer, WS_PING_INTERVAL_MS, true);

if(len == 0){
NODE_DBG("len == 0");
return;
}

char *b = buf;
if (ws->frameBuffer != NULL) { // Append previous frameBuffer with new content
Expand Down Expand Up @@ -497,6 +501,10 @@ static void ws_initReceiveCallback(void *arg, char *buf, unsigned short len) {
struct espconn *conn = (struct espconn *) arg;
ws_info *ws = (ws_info *) conn->reverse;

if (len == 0){
NODE_DBG("len==0\n");
return;
}
// Check server is switch protocols
if (strstr(buf, WS_HTTP_SWITCH_PROTOCOL_HEADER) == NULL) {
NODE_DBG("Server is not switching protocols\n");
Expand Down

0 comments on commit c7f8c3b

Please sign in to comment.