Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Beyond Protocol
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Beyond AKA
Beyond Protocol
Commits
9da2399c
Commit
9da2399c
authored
2 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/
#20
' into 'main'
#20
WS parse error reporting See merge request beyondaka/beyond-protocol!24
parents
ca03c365
5739601b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/protocol/websocket.cpp
+10
-13
10 additions, 13 deletions
src/protocol/websocket.cpp
with
10 additions
and
13 deletions
src/protocol/websocket.cpp
+
10
−
13
View file @
9da2399c
...
@@ -42,6 +42,7 @@ using ftl::net::internal::Connection_TLS;
...
@@ -42,6 +42,7 @@ using ftl::net::internal::Connection_TLS;
struct
wsheader_type
{
struct
wsheader_type
{
unsigned
header_size
;
unsigned
header_size
;
bool
fin
;
bool
fin
;
int
rsv
;
bool
mask
;
bool
mask
;
enum
opcode_type
{
enum
opcode_type
{
CONTINUATION
=
0x0
,
CONTINUATION
=
0x0
,
...
@@ -112,21 +113,21 @@ int ws_prepare(wsheader_type::opcode_type op, bool useMask, uint32_t mask,
...
@@ -112,21 +113,21 @@ int ws_prepare(wsheader_type::opcode_type op, bool useMask, uint32_t mask,
}
}
// parse ws header, returns true on success
// parse ws header, returns true on success
// TODO(Seb): return error code for different results (not enough bytes in buffer
void
ws_parse
(
uchar
*
data
,
size_t
len
,
wsheader_type
*
ws
)
{
// to build the header vs corrputed/invalid header)
if
(
len
<
2
)
throw
FTL_Error
(
"Websock header too small"
);
bool
ws_parse
(
uchar
*
data
,
size_t
len
,
wsheader_type
*
ws
)
{
if
(
len
<
2
)
return
false
;
ws
->
fin
=
(
data
[
0
]
&
0x80
)
==
0x80
;
ws
->
fin
=
(
data
[
0
]
&
0x80
)
==
0x80
;
ws
->
rsv
=
(
data
[
0
]
&
0x70
);
ws
->
opcode
=
(
wsheader_type
::
opcode_type
)
(
data
[
0
]
&
0x0f
);
ws
->
opcode
=
(
wsheader_type
::
opcode_type
)
(
data
[
0
]
&
0x0f
);
ws
->
mask
=
(
data
[
1
]
&
0x80
)
==
0x80
;
ws
->
mask
=
(
data
[
1
]
&
0x80
)
==
0x80
;
ws
->
N0
=
(
data
[
1
]
&
0x7f
);
ws
->
N0
=
(
data
[
1
]
&
0x7f
);
ws
->
header_size
=
2
+
(
ws
->
N0
==
126
?
2
:
0
)
+
(
ws
->
N0
==
127
?
8
:
0
)
+
(
ws
->
mask
?
4
:
0
);
ws
->
header_size
=
2
+
(
ws
->
N0
==
126
?
2
:
0
)
+
(
ws
->
N0
==
127
?
8
:
0
)
+
(
ws
->
mask
?
4
:
0
);
if
(
len
<
ws
->
header_size
)
return
false
;
if
(
len
<
ws
->
header_size
)
throw
FTL_Error
(
"Websock header too small"
);
if
(
ws
->
rsv
!=
0
)
throw
FTL_Error
(
"WS header reserved not zero"
);
// invalid opcode, corrupted header?
// invalid opcode, corrupted header?
if
((
ws
->
opcode
>
10
)
||
((
ws
->
opcode
>
2
)
&&
(
ws
->
opcode
<
8
)))
return
false
;
if
((
ws
->
opcode
>
10
)
||
((
ws
->
opcode
>
2
)
&&
(
ws
->
opcode
<
8
)))
throw
FTL_Error
(
"Websock opcode invalid"
)
;
int
i
=
0
;
int
i
=
0
;
if
(
ws
->
N0
<
126
)
{
if
(
ws
->
N0
<
126
)
{
...
@@ -161,13 +162,11 @@ bool ws_parse(uchar *data, size_t len, wsheader_type *ws) {
...
@@ -161,13 +162,11 @@ bool ws_parse(uchar *data, size_t len, wsheader_type *ws) {
ws
->
masking_key
[
2
]
=
0
;
ws
->
masking_key
[
2
]
=
0
;
ws
->
masking_key
[
3
]
=
0
;
ws
->
masking_key
[
3
]
=
0
;
}
}
return
true
;
}
}
// same as above, pointer type casted to unsigned
// same as above, pointer type casted to unsigned
bool
ws_parse
(
char
*
data
,
size_t
len
,
wsheader_type
*
ws
)
{
void
ws_parse
(
char
*
data
,
size_t
len
,
wsheader_type
*
ws
)
{
return
ws_parse
(
reinterpret_cast
<
unsigned
char
*>
(
data
),
len
,
ws
);
ws_parse
(
reinterpret_cast
<
unsigned
char
*>
(
data
),
len
,
ws
);
}
}
...
@@ -289,9 +288,7 @@ bool WebSocketBase<SocketT>::prepare_next(char* data, size_t data_len, size_t& o
...
@@ -289,9 +288,7 @@ bool WebSocketBase<SocketT>::prepare_next(char* data, size_t data_len, size_t& o
if
(
data_len
<
14
)
{
return
false
;
}
if
(
data_len
<
14
)
{
return
false
;
}
wsheader_type
header
;
wsheader_type
header
;
if
(
!
ws_parse
(
data
,
data_len
,
&
header
))
{
ws_parse
(
data
,
data_len
,
&
header
);
throw
FTL_Error
(
"corrupted WS header"
);
}
if
((
header
.
N
+
header
.
header_size
)
>
data_len
)
{
if
((
header
.
N
+
header
.
header_size
)
>
data_len
)
{
/*LOG(WARNING) << "buffered: " << data_len
/*LOG(WARNING) << "buffered: " << data_len
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment