Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "utils.h"
#include "compat.h"

// maximum allowed size for a single WebSocket message (bytes)
#define MAX_MESSAGE_SIZE (10 * 1024 * 1024)

// initial message list
static char initial_cmds[] = {SET_WINDOW_TITLE, SET_PREFERENCES};

Expand Down Expand Up @@ -286,10 +289,21 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,

case LWS_CALLBACK_RECEIVE:
if (pss->buffer == NULL) {
if (len > MAX_MESSAGE_SIZE) {
lwsl_warn("WS message too large: %zu bytes (max %d)\n", len, MAX_MESSAGE_SIZE);
return -1;
}
pss->buffer = xmalloc(len);
pss->len = len;
memcpy(pss->buffer, in, len);
} else {
if (pss->len + len > MAX_MESSAGE_SIZE) {
lwsl_warn("WS message too large: %zu bytes (max %d)\n", pss->len + len, MAX_MESSAGE_SIZE);
free(pss->buffer);
pss->buffer = NULL;
pss->len = 0;
return -1;
}
pss->buffer = xrealloc(pss->buffer, pss->len + len);
memcpy(pss->buffer + pss->len, in, len);
pss->len += len;
Expand Down