[Pkg-telepathy-commits] [libnice] 139/265: agent: Use locally allocated memory if the application buffer is not big enough for one STUN packet

Simon McVittie smcv at debian.org
Wed May 14 12:05:01 UTC 2014


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian
in repository libnice.

commit 26129cf69a1402fa74a5e7b72ea4452c514b751a
Author: Olivier Crête <olivier.crete at collabora.com>
Date:   Thu Feb 20 01:40:30 2014 -0500

    agent: Use locally allocated memory if the application buffer is not big enough for one STUN packet
---
 agent/agent.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/agent/agent.c b/agent/agent.c
index 54bc0c3..fbdefdb 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -2895,6 +2895,22 @@ output_message_get_size (const NiceOutputMessage *message)
   return message_len;
 }
 
+static gsize
+input_message_get_size (const NiceInputMessage *message)
+{
+  guint i;
+  gsize message_len = 0;
+
+  /* Find the total size of the message */
+  for (i = 0;
+       (message->n_buffers >= 0 && i < (guint) message->n_buffers) ||
+           (message->n_buffers < 0 && message->buffers[i].buffer != NULL);
+       i++)
+    message_len += message->buffers[i].size;
+
+  return message_len;
+}
+
 /*
  * nice_input_message_iter_reset:
  * @iter: a #NiceInputMessageIter
@@ -3047,6 +3063,8 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent,
   gboolean received_enough = FALSE, error_reported = FALSE;
   gboolean all_sockets_would_block = FALSE;
   GError *child_error = NULL;
+  NiceInputMessage *messages_orig = NULL;
+  guint i;
 
   g_return_val_if_fail (NICE_IS_AGENT (agent), -1);
   g_return_val_if_fail (stream_id >= 1, -1);
@@ -3059,6 +3077,24 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent,
   if (n_messages == 0)
     return 0;
 
+  /* Receive buffer size must be at least 1280 for STUN */
+  if (!agent->reliable) {
+    for (i = 0; i < n_messages; i++) {
+      if (input_message_get_size (&messages[i]) < 1280) {
+        GInputVector *vec;
+
+        if (messages_orig == NULL)
+          messages_orig = g_memdup (messages,
+              sizeof (NiceInputMessage) * n_messages);
+        vec = g_slice_new (GInputVector);
+        vec->buffer = g_slice_alloc (1280);
+        vec->size = 1280;
+        messages[i].buffers = vec;
+        messages[i].n_buffers = 1;
+      }
+    }
+  }
+
   agent_lock ();
 
   if (!agent_find_component (agent, stream_id, component_id,
@@ -3185,6 +3221,25 @@ done:
 
   agent_unlock ();
 
+  if (messages_orig) {
+    for (i = 0; i < n_messages; i++) {
+      if (messages[i].buffers != messages_orig[i].buffers) {
+        g_assert_cmpint (messages[i].n_buffers, ==, 1);
+
+        memcpy_buffer_to_input_message (&messages_orig[i],
+            messages[i].buffers[0].buffer, messages[i].length);
+
+        g_slice_free1 (1280, messages[i].buffers[0].buffer);
+        g_slice_free (GInputVector, messages[i].buffers);
+
+        messages[i].buffers = messages_orig[i].buffers;
+        messages[i].n_buffers = messages_orig[i].n_buffers;
+        messages[i].length = messages_orig[i].length;
+      }
+    }
+    g_free (messages_orig);
+  }
+
   return n_valid_messages;
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/libnice.git



More information about the Pkg-telepathy-commits mailing list