Fix crash when discovering peer reflexive candidates in RFC compat
authorYouness Alaoui <youness.alaoui@collabora.co.uk>
Wed, 9 Apr 2014 03:56:39 +0000 (23:56 -0400)
committerOlivier CrĂȘte <olivier.crete@ocrete.ca>
Thu, 15 May 2014 13:44:00 +0000 (09:44 -0400)
agent/conncheck.c
agent/conncheck.h
agent/discovery.c

index 8907448..7c1080b 100644 (file)
@@ -1318,8 +1318,8 @@ static void priv_add_new_check_pair (NiceAgent *agent, guint stream_id, Componen
   }
 }
 
-static NiceCandidateTransport
-priv_match_transport (NiceCandidateTransport transport)
+NiceCandidateTransport
+conn_check_match_transport (NiceCandidateTransport transport)
 {
   switch (transport) {
     case NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE:
@@ -1355,7 +1355,7 @@ static gboolean priv_conn_check_add_for_candidate_pair (NiceAgent *agent, guint
     return FALSE;
   }
   /* note: match pairs only if transport and address family are the same */
-  if (local->transport == priv_match_transport (remote->transport) &&
+  if (local->transport == conn_check_match_transport (remote->transport) &&
      local->addr.s.addr.sa_family == remote->addr.s.addr.sa_family) {
 
     nice_debug ("Agent %p, Adding check pair between %s and %s", agent,
@@ -2966,6 +2966,13 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
       break;
     }
   }
+  for (i = component->local_candidates; i; i = i->next) {
+    NiceCandidate *cand = i->data;
+    if (cand->sockptr == nicesock) {
+      local_candidate = cand;
+      break;
+    }
+  }
 
   if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE ||
       agent->compatibility == NICE_COMPATIBILITY_MSN ||
index 5da069e..ab4f4e7 100644 (file)
@@ -91,5 +91,6 @@ void conn_check_prune_stream (NiceAgent *agent, Stream *stream);
 gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, Component *component, NiceSocket *udp_socket, const NiceAddress *from, gchar *buf, guint len);
 gint conn_check_compare (const CandidateCheckPair *a, const CandidateCheckPair *b);
 void conn_check_remote_candidates_set(NiceAgent *agent);
+NiceCandidateTransport conn_check_match_transport (NiceCandidateTransport transport);
 
 #endif /*_NICE_CONNCHECK_H */
index f63d3dc..94b885e 100644 (file)
@@ -763,20 +763,27 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
   Component *component,
   guint32 priority,
   const NiceAddress *remote_address,
-  NiceSocket *udp_socket,
+  NiceSocket *nicesock,
   NiceCandidate *local,
   NiceCandidate *remote)
 {
   NiceCandidate *candidate;
 
-  /* XXX: for use compiler */
-  (void)udp_socket;
-
   candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_PEER_REFLEXIVE);
 
   candidate->addr = *remote_address;
   candidate->base_addr = *remote_address;
-  candidate->transport = remote->transport;
+  if (remote)
+    candidate->transport = remote->transport;
+  else if (local)
+    candidate->transport = conn_check_match_transport (local->transport);
+  else {
+    if (nicesock->type == NICE_SOCKET_TYPE_UDP_BSD ||
+        nicesock->type == NICE_SOCKET_TYPE_TURN)
+      candidate->transport = NICE_CANDIDATE_TRANSPORT_UDP;
+    else
+      candidate->transport = NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE;
+  }
   candidate->stream_id = stream->id;
   candidate->component_id = component->id;