Skip to content

Commit cdc439b

Browse files
author
robert
committed
Websocket offset validation enhancement
1 parent 539d080 commit cdc439b

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

mongoose.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19719,7 +19719,7 @@ static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data) {
1971919719
// Remove non-fragmented frame
1972019720
if (final && op) mg_iobuf_del(&c->recv, ofs, len);
1972119721
// Last chunk of the fragmented frame
19722-
if (final && !op) {
19722+
if (final && !op && (ofs > 0)) {
1972319723
m.flags = c->recv.buf[0];
1972419724
m.data = mg_str_n((char *) &c->recv.buf[1], (size_t) (ofs - 1));
1972519725
mg_call(c, MG_EV_WS_MSG, &m);

src/ws.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data) {
219219
// Remove non-fragmented frame
220220
if (final && op) mg_iobuf_del(&c->recv, ofs, len);
221221
// Last chunk of the fragmented frame
222-
if (final && !op) {
222+
if (final && !op && (ofs > 0)) {
223223
m.flags = c->recv.buf[0];
224224
m.data = mg_str_n((char *) &c->recv.buf[1], (size_t) (ofs - 1));
225225
mg_call(c, MG_EV_WS_MSG, &m);

test/unit_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ static void wcb(struct mg_connection *c, int ev, void *ev_data) {
811811
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
812812
struct mg_str *wsproto = mg_http_get_header(hm, "Sec-WebSocket-Protocol");
813813
ASSERT(wsproto != NULL);
814+
mg_ws_send(c, "hello", 0, 0);
814815
mg_ws_printf(c, WEBSOCKET_OP_BINARY, "%.3s", "boo!!!!");
815816
mg_ws_printf(c, WEBSOCKET_OP_BINARY, "%s", "foobar");
816817
mg_ws_send(c, "", 0, WEBSOCKET_OP_PING);

0 commit comments

Comments
 (0)