Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nginx-push-stream-module
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
nginx-push-stream-module
Commits
4516ca59
Commit
4516ca59
authored
Jul 05, 2015
by
Wandenberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ignore non valid utf8 messages published on websocket connections
parent
f14dba7c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
0 deletions
+72
-0
ngx_http_push_stream_module_utils.h
include/ngx_http_push_stream_module_utils.h
+2
-0
websocket_spec.rb
misc/spec/subscriber/websocket_spec.rb
+39
-0
ngx_http_push_stream_module_utils.c
src/ngx_http_push_stream_module_utils.c
+27
-0
ngx_http_push_stream_module_websocket.c
src/ngx_http_push_stream_module_websocket.c
+4
-0
No files found.
include/ngx_http_push_stream_module_utils.h
View file @
4516ca59
...
...
@@ -309,4 +309,6 @@ ngx_http_push_stream_requested_channel_t *ngx_http_push_stream_parse_channels_id
ngx_int_t
ngx_http_push_stream_create_shmtx
(
ngx_shmtx_t
*
mtx
,
ngx_shmtx_sh_t
*
addr
,
u_char
*
name
);
ngx_flag_t
ngx_http_push_stream_is_utf8
(
u_char
*
p
,
size_t
n
);
#endif
/* NGX_HTTP_PUSH_STREAM_MODULE_UTILS_H_ */
misc/spec/subscriber/websocket_spec.rb
View file @
4516ca59
...
...
@@ -635,4 +635,43 @@ describe "Subscriber WebSocket" do
end
end
end
it
"should accept non latin characters"
do
channel
=
'ch_test_publish_non_latin'
nginx_run_server
(
config
)
do
|
conf
|
EventMachine
.
run
do
ws
=
WebSocket
::
EventMachine
::
Client
.
connect
(
:uri
=>
"ws://
#{
nginx_host
}
:
#{
nginx_port
}
/ws/
#{
channel
}
"
)
ws
.
onmessage
do
|
text
,
type
|
expect
(
text
).
to
eq
(
"
\xD8\xA3\xD9\x8E\xD8\xA8\xD9\x92\xD8\xAC\xD9\x8E\xD8\xAF\xD9\x90\xD9\x8A\xD9\x8E\xD9\x91\xD8\xA9
\xD8\xB9\xD9\x8E
"
)
EventMachine
.
stop
end
EM
.
add_timer
(
1
)
do
ws
.
send
"
\xD8\xA3\xD9\x8E\xD8\xA8\xD9\x92\xD8\xAC\xD9\x8E\xD8\xAF\xD9\x90\xD9\x8A\xD9\x8E\xD9\x91\xD8\xA9
\xD8\xB9\xD9\x8E
"
end
end
end
end
it
"should reject an invalid utf8 sequence"
do
channel
=
'ch_test_publish_invalid_utf8'
nginx_run_server
(
config
)
do
|
conf
|
EventMachine
.
run
do
ws
=
WebSocket
::
EventMachine
::
Client
.
connect
(
:uri
=>
"ws://
#{
nginx_host
}
:
#{
nginx_port
}
/ws/
#{
channel
}
"
)
ws
.
onmessage
do
|
text
,
type
|
fail
(
"Should not have received the '
#{
text
.
force_encoding
(
'UTF-8'
)
}
'"
)
end
ws
.
onclose
do
EventMachine
.
stop
end
EM
.
add_timer
(
1
)
do
ws
.
send
"
\xA3\xD9\x8E\xD8\xA8\xD9\x92\xD8\xAC\xD9\x8E\xD8\xAF\xD9\x90\xD9\x8A\xD9\x8E\xD9\x91\xD8\xA9
\xD8\xB9\xD9\x8E
"
end
end
end
end
end
src/ngx_http_push_stream_module_utils.c
View file @
4516ca59
...
...
@@ -2311,3 +2311,30 @@ ngx_http_push_stream_create_shmtx(ngx_shmtx_t *mtx, ngx_shmtx_sh_t *addr, u_char
return
NGX_OK
;
}
ngx_flag_t
ngx_http_push_stream_is_utf8
(
u_char
*
p
,
size_t
n
)
{
u_char
c
,
*
last
;
size_t
len
;
last
=
p
+
n
;
for
(
len
=
0
;
p
<
last
;
len
++
)
{
c
=
*
p
;
if
(
c
<
0x80
)
{
p
++
;
continue
;
}
if
(
ngx_utf8_decode
(
&
p
,
n
)
>
0x10ffff
)
{
/* invalid UTF-8 */
return
0
;
}
}
return
1
;
}
src/ngx_http_push_stream_module_websocket.c
View file @
4516ca59
...
...
@@ -287,6 +287,10 @@ ngx_http_push_stream_websocket_reading(ngx_http_request_t *r)
}
}
if
(
!
ngx_http_push_stream_is_utf8
(
ctx
->
frame
->
payload
,
ctx
->
frame
->
payload_len
))
{
goto
finalize
;
}
for
(
q
=
ngx_queue_head
(
&
ctx
->
subscriber
->
subscriptions
);
q
!=
ngx_queue_sentinel
(
&
ctx
->
subscriber
->
subscriptions
);
q
=
ngx_queue_next
(
q
))
{
ngx_http_push_stream_subscription_t
*
subscription
=
ngx_queue_data
(
q
,
ngx_http_push_stream_subscription_t
,
queue
);
if
(
subscription
->
channel
->
for_events
)
{
...
...
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