[PATCH spice-server v2 1/2] tests: Check leaks in spice_server_add_ssl_client

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently is possible to trigger a leak passing an invalid connection.
This can happen if the client open a connection and then closes it
without writing or reading any data.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/tests/Makefile.am  |  1 +
 server/tests/test-leaks.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)

Changes since v1:
- improve commit message.

diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
index 01e636265..d50c590c3 100644
--- a/server/tests/Makefile.am
+++ b/server/tests/Makefile.am
@@ -138,6 +138,7 @@ test_vdagent_CPPFLAGS =			\
 test_codecs_parsing_CPPFLAGS = $(test_vdagent_CPPFLAGS)
 test_qxl_parsing_CPPFLAGS = $(test_vdagent_CPPFLAGS)
 test_fail_on_null_core_interface_CPPFLAGS = $(test_vdagent_CPPFLAGS)
+test_leaks_CPPFLAGS = $(test_vdagent_CPPFLAGS)
 
 if HAVE_GSTREAMER
 test_gst_SOURCES = test-gst.c \
diff --git a/server/tests/test-leaks.c b/server/tests/test-leaks.c
index 74ab2afd5..04dcac4f4 100644
--- a/server/tests/test-leaks.c
+++ b/server/tests/test-leaks.c
@@ -29,6 +29,7 @@
  * For cleaner output you should suppress GLib checks with glib.supp file.
  */
 #include <config.h>
+#include <unistd.h>
 #include <spice.h>
 
 #include "test-glib-compat.h"
@@ -42,6 +43,7 @@ static void server_leaks(void)
     int result;
     SpiceCoreInterface *core;
     SpiceServer *server = spice_server_new();
+    int sv[2];
 
     g_assert_nonnull(server);
 
@@ -64,6 +66,16 @@ static void server_leaks(void)
     result = spice_server_set_channel_security(server, "main", SPICE_CHANNEL_SECURITY_SSL);
     g_assert_cmpint(result, ==, 0);
 
+    /* spice_server_add_ssl_client should not leak when it's given a disconnected socket */
+    g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+                          "*SSL_accept failed*");
+    g_assert_cmpint(socketpair(AF_LOCAL, SOCK_STREAM, 0, sv), ==, 0);
+    close(sv[1]);
+    result = spice_server_add_ssl_client(server, sv[0], 1);
+    g_assert_cmpint(result, ==, -1);
+    /* if the function fails, it should not close the socket */
+    g_assert_cmpint(close(sv[0]), ==, 0);
+
     spice_server_destroy(server);
     basic_event_loop_destroy();
 }
-- 
2.13.5

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]