summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.com>2018-10-21 12:01:55 +0200
committerOlivier CrĂȘte <olivier.crete@collabora.com>2018-11-21 03:23:59 -0500
commitbeea9b38be4efb5723d75d63d5a63241efd505cb (patch)
treebda91dd2425e82d5a394a413991247c3b6b1a6a9
parenta05e9dcff179c2c4c6fc3feb422c20b07e936576 (diff)
downloadlibnice-beea9b38be4efb5723d75d63d5a63241efd505cb.tar.gz
tcp-passive: Clear connection on child closing
If this isn't done, then there may be invalid points left inside the passive socket which could be used and cause a crash. Fixes #33
-rw-r--r--socket/tcp-bsd.c17
-rw-r--r--socket/tcp-bsd.h3
-rw-r--r--socket/tcp-passive.c9
-rw-r--r--socket/tcp-passive.h3
4 files changed, 32 insertions, 0 deletions
diff --git a/socket/tcp-bsd.c b/socket/tcp-bsd.c
index 8f3ac89..49f5f25 100644
--- a/socket/tcp-bsd.c
+++ b/socket/tcp-bsd.c
@@ -46,6 +46,8 @@
#include "agent-priv.h"
#include "socket-priv.h"
+#include "tcp-passive.h"
+
#include <string.h>
#include <errno.h>
#include <fcntl.h>
@@ -70,6 +72,7 @@ typedef struct {
gboolean reliable;
NiceSocketWritableCb writable_cb;
gpointer writable_data;
+ NiceSocket *passive_parent;
} TcpPriv;
#define MAX_QUEUE_LENGTH 20
@@ -226,6 +229,10 @@ socket_close (NiceSocket *sock)
g_source_unref (priv->io_source);
}
+ if (priv->passive_parent) {
+ nice_tcp_passive_socket_remove_connection (priv->passive_parent, &priv->remote_addr);
+ }
+
nice_socket_free_send_queue (&priv->send_queue);
if (priv->context)
@@ -458,3 +465,13 @@ socket_send_more (
g_mutex_unlock (&mutex);
return TRUE;
}
+
+void
+nice_tcp_bsd_socket_set_passive_parent (NiceSocket *sock, NiceSocket *passive_parent)
+{
+ TcpPriv *priv = sock->priv;
+
+ g_assert (priv->passive_parent == NULL);
+
+ priv->passive_parent = passive_parent;
+}
diff --git a/socket/tcp-bsd.h b/socket/tcp-bsd.h
index 58349cc..615b759 100644
--- a/socket/tcp-bsd.h
+++ b/socket/tcp-bsd.h
@@ -49,6 +49,9 @@ NiceSocket *
nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock,
NiceAddress *remote_addr, NiceAddress *local_addr, gboolean reliable);
+void
+nice_tcp_bsd_socket_set_passive_parent (NiceSocket *socket, NiceSocket *passive_parent);
+
G_END_DECLS
#endif /* _TCP_BSD_H */
diff --git a/socket/tcp-passive.c b/socket/tcp-passive.c
index 131ff4b..d7684ad 100644
--- a/socket/tcp-passive.c
+++ b/socket/tcp-passive.c
@@ -310,6 +310,8 @@ nice_tcp_passive_socket_accept (NiceSocket *sock)
if (new_socket) {
NiceAddress *key = nice_address_dup (&remote_addr);
+ nice_tcp_bsd_socket_set_passive_parent (new_socket, sock);
+
nice_socket_set_writable_callback (new_socket, _child_writable_cb, sock);
g_hash_table_insert (priv->connections, key, new_socket);
}
@@ -329,3 +331,10 @@ static guint nice_address_hash (const NiceAddress * key)
return hash;
}
+
+void nice_tcp_passive_socket_remove_connection (NiceSocket *sock, const NiceAddress *to)
+{
+ TcpPassivePriv *priv = sock->priv;
+
+ g_hash_table_remove (priv->connections, to);
+}
diff --git a/socket/tcp-passive.h b/socket/tcp-passive.h
index 37e780b..914f081 100644
--- a/socket/tcp-passive.h
+++ b/socket/tcp-passive.h
@@ -46,6 +46,9 @@ G_BEGIN_DECLS
NiceSocket * nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr);
NiceSocket * nice_tcp_passive_socket_accept (NiceSocket *socket);
+void nice_tcp_passive_socket_remove_connection (NiceSocket *socket,
+ const NiceAddress *to);
+
G_END_DECLS