Skip to content

Commit

Permalink
rtsp-server: fixed segfault in gst_rtsp_server_create_socket
Browse files Browse the repository at this point in the history
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
  • Loading branch information
booboo0706 authored and Wim Taymans committed Aug 20, 2012
1 parent 41f9875 commit 50e4c7e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gst/rtsp-server/rtsp-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -696,7 +699,7 @@ gst_rtsp_server_create_socket (GstRTSPServer * server,
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);
Expand Down
34 changes: 34 additions & 0 deletions tests/check/gst/rtspserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
Expand Down

0 comments on commit 50e4c7e

Please sign in to comment.