Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
libnice
Commits
b353f30c
Commit
b353f30c
authored
Dec 06, 2020
by
Fabrice Bellet
Committed by
Olivier Crête
Apr 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
udp-turn: don't allocate large arrays on the stack
parent
48dac0d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
socket/udp-turn.c
socket/udp-turn.c
+11
-4
No files found.
socket/udp-turn.c
View file @
b353f30c
...
@@ -108,6 +108,7 @@ typedef struct {
...
@@ -108,6 +108,7 @@ typedef struct {
GByteArray
*
fragment_buffer
;
GByteArray
*
fragment_buffer
;
NiceAddress
from
;
NiceAddress
from
;
uint8_t
*
send_buffer
;
}
UdpTurnPriv
;
}
UdpTurnPriv
;
...
@@ -256,6 +257,8 @@ nice_udp_turn_socket_new (GMainContext *ctx, NiceAddress *addr,
...
@@ -256,6 +257,8 @@ nice_udp_turn_socket_new (GMainContext *ctx, NiceAddress *addr,
(
GDestroyNotify
)
nice_address_free
,
(
GDestroyNotify
)
nice_address_free
,
priv_send_data_queue_destroy
);
priv_send_data_queue_destroy
);
priv
->
send_buffer
=
g_malloc
(
STUN_MAX_MESSAGE_SIZE
);
sock
->
type
=
NICE_SOCKET_TYPE_UDP_TURN
;
sock
->
type
=
NICE_SOCKET_TYPE_UDP_TURN
;
sock
->
fileno
=
NULL
;
sock
->
fileno
=
NULL
;
sock
->
addr
=
*
addr
;
sock
->
addr
=
*
addr
;
...
@@ -333,6 +336,8 @@ socket_close (NiceSocket *sock)
...
@@ -333,6 +336,8 @@ socket_close (NiceSocket *sock)
g_byte_array_free
(
priv
->
fragment_buffer
,
TRUE
);
g_byte_array_free
(
priv
->
fragment_buffer
,
TRUE
);
}
}
g_free
(
priv
->
send_buffer
);
g_free
(
priv
);
g_free
(
priv
);
sock
->
priv
=
NULL
;
sock
->
priv
=
NULL
;
...
@@ -787,7 +792,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
...
@@ -787,7 +792,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
{
{
UdpTurnPriv
*
priv
=
(
UdpTurnPriv
*
)
sock
->
priv
;
UdpTurnPriv
*
priv
=
(
UdpTurnPriv
*
)
sock
->
priv
;
StunMessage
msg
;
StunMessage
msg
;
uint8_t
buffer
[
STUN_MAX_MESSAGE_SIZE
]
;
uint8_t
*
buffer
;
size_t
msg_len
;
size_t
msg_len
;
union
{
union
{
struct
sockaddr_storage
storage
;
struct
sockaddr_storage
storage
;
...
@@ -800,6 +805,8 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
...
@@ -800,6 +805,8 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
/* Make sure socket has not been freed: */
/* Make sure socket has not been freed: */
g_assert
(
sock
->
priv
!=
NULL
);
g_assert
(
sock
->
priv
!=
NULL
);
buffer
=
priv
->
send_buffer
;
for
(
i
=
priv
->
channels
;
i
;
i
=
i
->
next
)
{
for
(
i
=
priv
->
channels
;
i
;
i
=
i
->
next
)
{
ChannelBinding
*
b
=
i
->
data
;
ChannelBinding
*
b
=
i
->
data
;
if
(
nice_address_equal
(
&
b
->
peer
,
to
))
{
if
(
nice_address_equal
(
&
b
->
peer
,
to
))
{
...
@@ -815,7 +822,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
...
@@ -815,7 +822,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_RFC5766
)
{
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_RFC5766
)
{
gsize
message_len
=
output_message_get_size
(
message
);
gsize
message_len
=
output_message_get_size
(
message
);
if
(
message_len
+
sizeof
(
uint32_t
)
<=
sizeof
(
buffer
)
)
{
if
(
message_len
+
sizeof
(
uint32_t
)
<=
STUN_MAX_MESSAGE_SIZE
)
{
guint
j
;
guint
j
;
uint16_t
len16
,
channel16
;
uint16_t
len16
,
channel16
;
gsize
message_offset
=
0
;
gsize
message_offset
=
0
;
...
@@ -861,7 +868,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
...
@@ -861,7 +868,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
if
(
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9
||
if
(
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9
||
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_RFC5766
)
{
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_RFC5766
)
{
if
(
!
stun_agent_init_indication
(
&
priv
->
agent
,
&
msg
,
if
(
!
stun_agent_init_indication
(
&
priv
->
agent
,
&
msg
,
buffer
,
sizeof
(
buffer
)
,
STUN_IND_SEND
))
buffer
,
STUN_MAX_MESSAGE_SIZE
,
STUN_IND_SEND
))
goto
error
;
goto
error
;
if
(
stun_message_append_xor_addr
(
&
msg
,
STUN_ATTRIBUTE_PEER_ADDRESS
,
if
(
stun_message_append_xor_addr
(
&
msg
,
STUN_ATTRIBUTE_PEER_ADDRESS
,
&
sa
.
storage
,
sizeof
(
sa
))
!=
&
sa
.
storage
,
sizeof
(
sa
))
!=
...
@@ -869,7 +876,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
...
@@ -869,7 +876,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
goto
error
;
goto
error
;
}
else
{
}
else
{
if
(
!
stun_agent_init_request
(
&
priv
->
agent
,
&
msg
,
if
(
!
stun_agent_init_request
(
&
priv
->
agent
,
&
msg
,
buffer
,
sizeof
(
buffer
)
,
STUN_SEND
))
buffer
,
STUN_MAX_MESSAGE_SIZE
,
STUN_SEND
))
goto
error
;
goto
error
;
if
(
stun_message_append32
(
&
msg
,
STUN_ATTRIBUTE_MAGIC_COOKIE
,
if
(
stun_message_append32
(
&
msg
,
STUN_ATTRIBUTE_MAGIC_COOKIE
,
...
...
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