summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.com>2014-03-27 07:54:32 (GMT)
committerOlivier CrĂȘte <olivier.crete@collabora.com>2014-03-31 20:40:44 (GMT)
commit3a1a640667f8c07c42bc35a1d6bc1da026366603 (patch)
tree6cb203bcffc71c2df0f3df176b757cfbf1f1dd1c
parent93731baf36f7ebc8e4c464b6a61db6ec3c7bf411 (diff)
downloadlibnice-3a1a640667f8c07c42bc35a1d6bc1da026366603.tar.gz
libnice-3a1a640667f8c07c42bc35a1d6bc1da026366603.tar.xz
turn-tcp: Don't corrupt messages
-rw-r--r--socket/tcp-turn.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/socket/tcp-turn.c b/socket/tcp-turn.c
index 8532538..3021009 100644
--- a/socket/tcp-turn.c
+++ b/socket/tcp-turn.c
@@ -234,6 +234,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
gint ret;
guint n_bufs;
guint16 header_buf;
+ guint offset = 0;
/* Count the number of buffers. */
if (message->n_buffers == -1) {
@@ -247,30 +248,15 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
/* Allocate a new array of buffers, covering all the buffers in the input
* @message, but with an additional one for a header and one for a footer. */
- local_bufs = g_malloc_n (n_bufs + 2, sizeof (GOutputVector));
+ local_bufs = g_malloc_n (n_bufs + 1, sizeof (GOutputVector));
local_message.buffers = local_bufs;
- local_message.n_buffers = n_bufs + 2;
+ local_message.n_buffers = n_bufs + 1;
- /* Copy the existing buffers across. */
- for (j = 0; j < n_bufs; j++) {
- local_bufs[j + 1].buffer = message->buffers[j].buffer;
- local_bufs[j + 1].size = message->buffers[j].size;
- }
-
- /* Header buffer. */
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE) {
- header_buf = htons (output_message_get_size (message));
-
local_bufs[0].buffer = &header_buf;
local_bufs[0].size = sizeof (header_buf);
- } else {
- /* Skip over the allocated header buffer. */
- local_message.buffers++;
- local_message.n_buffers--;
- }
-
- /* Tail buffer. */
- if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 ||
+ offset = 1;
+ } else if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 ||
priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) {
gsize message_len = output_message_get_size (message);
gsize padlen = (message_len % 4) ? 4 - (message_len % 4) : 0;
@@ -278,10 +264,16 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
local_bufs[n_bufs].buffer = &padbuf;
local_bufs[n_bufs].size = padlen;
} else {
- /* Skip over the allocated tail buffer. */
- local_message.n_buffers--;
+ local_message.n_buffers = n_bufs;
}
+ /* Copy the existing buffers across. */
+ for (j = 0; j < n_bufs; j++) {
+ local_bufs[j + offset].buffer = message->buffers[j].buffer;
+ local_bufs[j + offset].size = message->buffers[j].size;
+ }
+
+
ret = nice_socket_send_messages (priv->base_socket, to, &local_message, 1);
g_free (local_bufs);