Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
5e787114
Commit
5e787114
authored
May 18, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed masking in websocket code
parent
b4a622cf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
mongoose.c
mongoose.c
+17
-5
No files found.
mongoose.c
View file @
5e787114
...
@@ -3818,9 +3818,9 @@ static void send_websocket_handshake(struct mg_connection *conn) {
...
@@ -3818,9 +3818,9 @@ static void send_websocket_handshake(struct mg_connection *conn) {
static
void
read_websocket
(
struct
mg_connection
*
conn
)
{
static
void
read_websocket
(
struct
mg_connection
*
conn
)
{
unsigned
char
*
buf
=
(
unsigned
char
*
)
conn
->
buf
+
conn
->
request_len
;
unsigned
char
*
buf
=
(
unsigned
char
*
)
conn
->
buf
+
conn
->
request_len
;
int
n
,
stop
=
0
;
int
bits
,
n
,
stop
=
0
;
size_t
i
,
len
,
mask_len
,
data_len
,
header_len
,
body_len
;
size_t
i
,
len
,
mask_len
,
data_len
,
header_len
,
body_len
;
char
mem
[
4
*
1024
],
*
data
;
char
mem
[
4
*
1024
],
mask
[
4
],
*
data
;
assert
(
conn
->
content_len
==
0
);
assert
(
conn
->
content_len
==
0
);
while
(
!
stop
)
{
while
(
!
stop
)
{
...
@@ -3841,6 +3841,14 @@ static void read_websocket(struct mg_connection *conn) {
...
@@ -3841,6 +3841,14 @@ static void read_websocket(struct mg_connection *conn) {
}
}
}
}
// Data layout is as follows:
// conn->buf buf
// v v frame1 | frame2
// |---------------------|----------------|--------------|-------
// | |<--header_len-->|<--data_len-->|
// |<-conn->request_len->|<-----body_len----------->|
// |<-------------------conn->data_len------------->|
if
(
header_len
>
0
)
{
if
(
header_len
>
0
)
{
// Allocate space to hold websocket payload
// Allocate space to hold websocket payload
data
=
mem
;
data
=
mem
;
...
@@ -3850,6 +3858,10 @@ static void read_websocket(struct mg_connection *conn) {
...
@@ -3850,6 +3858,10 @@ static void read_websocket(struct mg_connection *conn) {
break
;
break
;
}
}
// Save mask and bits, otherwise it may be clobbered by memmove below
bits
=
buf
[
0
];
memcpy
(
mask
,
buf
+
header_len
-
mask_len
,
mask_len
);
// Read frame payload into the allocated buffer.
// Read frame payload into the allocated buffer.
assert
(
body_len
>=
header_len
);
assert
(
body_len
>=
header_len
);
if
(
data_len
+
header_len
>
body_len
)
{
if
(
data_len
+
header_len
>
body_len
)
{
...
@@ -3868,15 +3880,15 @@ static void read_websocket(struct mg_connection *conn) {
...
@@ -3868,15 +3880,15 @@ static void read_websocket(struct mg_connection *conn) {
// Apply mask if necessary
// Apply mask if necessary
if
(
mask_len
>
0
)
{
if
(
mask_len
>
0
)
{
for
(
i
=
0
;
i
<
data_len
;
i
++
)
{
for
(
i
=
0
;
i
<
data_len
;
i
++
)
{
data
[
i
]
^=
buf
[
header_len
-
mask_len
+
(
i
%
4
)
];
data
[
i
]
^=
mask
[
i
%
4
];
}
}
}
}
// Exit the loop if callback signalled to exit,
// Exit the loop if callback signalled to exit,
// or "connection close" opcode received.
// or "connection close" opcode received.
if
((
conn
->
ctx
->
callbacks
.
websocket_data
!=
NULL
&&
if
((
conn
->
ctx
->
callbacks
.
websocket_data
!=
NULL
&&
!
conn
->
ctx
->
callbacks
.
websocket_data
(
conn
,
b
uf
[
0
]
,
data
,
data_len
))
||
!
conn
->
ctx
->
callbacks
.
websocket_data
(
conn
,
b
its
,
data
,
data_len
))
||
(
b
uf
[
0
]
&
0xf
)
==
8
)
{
// Opcode == 8, connection close
(
b
its
&
0xf
)
==
8
)
{
// Opcode == 8, connection close
stop
=
1
;
stop
=
1
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment