mirror of
https://github.com/cesanta/mongoose.git
synced 2025-06-08 01:42:52 +08:00
Websocket offset validation enhancement
This commit is contained in:
parent
539d080346
commit
cdc439bc38
@ -19719,7 +19719,7 @@ static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
// Remove non-fragmented frame
|
// Remove non-fragmented frame
|
||||||
if (final && op) mg_iobuf_del(&c->recv, ofs, len);
|
if (final && op) mg_iobuf_del(&c->recv, ofs, len);
|
||||||
// Last chunk of the fragmented frame
|
// Last chunk of the fragmented frame
|
||||||
if (final && !op) {
|
if (final && !op && (ofs > 0)) {
|
||||||
m.flags = c->recv.buf[0];
|
m.flags = c->recv.buf[0];
|
||||||
m.data = mg_str_n((char *) &c->recv.buf[1], (size_t) (ofs - 1));
|
m.data = mg_str_n((char *) &c->recv.buf[1], (size_t) (ofs - 1));
|
||||||
mg_call(c, MG_EV_WS_MSG, &m);
|
mg_call(c, MG_EV_WS_MSG, &m);
|
||||||
|
2
src/ws.c
2
src/ws.c
@ -219,7 +219,7 @@ static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
// Remove non-fragmented frame
|
// Remove non-fragmented frame
|
||||||
if (final && op) mg_iobuf_del(&c->recv, ofs, len);
|
if (final && op) mg_iobuf_del(&c->recv, ofs, len);
|
||||||
// Last chunk of the fragmented frame
|
// Last chunk of the fragmented frame
|
||||||
if (final && !op) {
|
if (final && !op && (ofs > 0)) {
|
||||||
m.flags = c->recv.buf[0];
|
m.flags = c->recv.buf[0];
|
||||||
m.data = mg_str_n((char *) &c->recv.buf[1], (size_t) (ofs - 1));
|
m.data = mg_str_n((char *) &c->recv.buf[1], (size_t) (ofs - 1));
|
||||||
mg_call(c, MG_EV_WS_MSG, &m);
|
mg_call(c, MG_EV_WS_MSG, &m);
|
||||||
|
@ -811,6 +811,7 @@ static void wcb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||||
struct mg_str *wsproto = mg_http_get_header(hm, "Sec-WebSocket-Protocol");
|
struct mg_str *wsproto = mg_http_get_header(hm, "Sec-WebSocket-Protocol");
|
||||||
ASSERT(wsproto != NULL);
|
ASSERT(wsproto != NULL);
|
||||||
|
mg_ws_send(c, "hello", 0, 0);
|
||||||
mg_ws_printf(c, WEBSOCKET_OP_BINARY, "%.3s", "boo!!!!");
|
mg_ws_printf(c, WEBSOCKET_OP_BINARY, "%.3s", "boo!!!!");
|
||||||
mg_ws_printf(c, WEBSOCKET_OP_BINARY, "%s", "foobar");
|
mg_ws_printf(c, WEBSOCKET_OP_BINARY, "%s", "foobar");
|
||||||
mg_ws_send(c, "", 0, WEBSOCKET_OP_PING);
|
mg_ws_send(c, "", 0, WEBSOCKET_OP_PING);
|
||||||
|
Loading…
Reference in New Issue
Block a user