rtsp-server: fixed segfault in gst_rtsp_server_create_socket

Do not assume that *error is set in g_socket_address_enumerator_next.
Added test_bind_already_in_use unit-test.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=681914
This commit is contained in:
Patricia Muscalu 2012-08-15 15:54:32 +02:00 committed by Wim Taymans
parent 41f9875366
commit 50e4c7e8c4
2 changed files with 39 additions and 2 deletions

View file

@ -594,7 +594,10 @@ gst_rtsp_server_create_socket (GstRTSPServer * server,
sockaddr =
g_socket_address_enumerator_next (enumerator, cancellable, error);
if (!sockaddr) {
GST_DEBUG_OBJECT (server, "no more addresses %s", (*error)->message);
if (!*error)
GST_DEBUG_OBJECT (server, "no more addresses %s", *error ? (*error)->message : "");
else
GST_DEBUG_OBJECT (server, "failed to retrieve next address %s", (*error)->message);
break;
}
@ -696,7 +699,7 @@ close_error:
g_error_free (sock_error);
}
if (bind_error) {
if (error == NULL)
if ((error == NULL) || (*error == NULL))
g_propagate_error (error, bind_error);
else
g_error_free (bind_error);

View file

@ -688,6 +688,39 @@ GST_START_TEST (test_play_without_session)
GST_END_TEST;
GST_START_TEST (test_bind_already_in_use)
{
GstRTSPServer *serv;
GSocketService *service;
GError *error = NULL;
guint16 port;
gchar *port_str;
serv = gst_rtsp_server_new ();
service = g_socket_service_new ();
/* bind service to port */
port = g_socket_listener_add_any_inet_port (G_SOCKET_LISTENER (service), NULL, &error);
g_assert_no_error (error);
port_str = g_strdup_printf ("%d\n", port);
/* try to bind server to the same port */
g_object_set (serv, "service", port_str, NULL);
g_free (port_str);
/* attach to default main context */
fail_unless (gst_rtsp_server_attach (serv, NULL) == 0);
/* cleanup */
g_object_unref (serv);
g_socket_listener_close (G_SOCKET_LISTENER (service));
g_object_unref (service);
}
GST_END_TEST;
static Suite *
rtspserver_suite (void)
{
@ -704,6 +737,7 @@ rtspserver_suite (void)
tcase_add_test (tc, test_setup_non_existing_stream);
tcase_add_test (tc, test_play);
tcase_add_test (tc, test_play_without_session);
tcase_add_test (tc, test_bind_already_in_use);
return s;
}