diff options
author | Patricia Muscalu <patricia@axis.com> | 2017-01-09 14:12:05 +0100 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2017-01-09 15:27:40 +0200 |
commit | f47e6ab9f69ec1c77f8875ca41ee5ff268ab06ab (patch) | |
tree | 698bd0e0564489defc103ccdc9cb68493ad8e8db | |
parent | b27e7c6b5bc7b5ab23ef5d833bd413ce7841db8b (diff) |
rtsp-stream: fixed segmenation fault in _get_server_port()
Calling function gst_rtsp_stream_get_server_port() results in
segmenation fault in the RTP/RTSP/TCP case.
Port that the server will use to receive RTCP makes only
sense in the UDP case, however the function should handle
the TCP case in a nicer way.
https://bugzilla.gnome.org/show_bug.cgi?id=776345
-rw-r--r-- | gst/rtsp-server/rtsp-stream.c | 9 | ||||
-rw-r--r-- | tests/check/gst/stream.c | 42 |
2 files changed, 49 insertions, 2 deletions
diff --git a/gst/rtsp-server/rtsp-stream.c b/gst/rtsp-server/rtsp-stream.c index ee92b84..6af69b4 100644 --- a/gst/rtsp-server/rtsp-stream.c +++ b/gst/rtsp-server/rtsp-stream.c @@ -1525,15 +1525,20 @@ gst_rtsp_stream_get_server_port (GstRTSPStream * stream, priv = stream->priv; g_return_if_fail (priv->joined_bin != NULL); + if (server_port) { + server_port->min = 0; + server_port->max = 0; + } + g_mutex_lock (&priv->lock); - if (family == G_SOCKET_FAMILY_IPV4) { + if (family == G_SOCKET_FAMILY_IPV4 && priv->server_addr_v4) { if (server_port) { server_port->min = priv->server_addr_v4->port; server_port->max = priv->server_addr_v4->port + priv->server_addr_v4->n_ports - 1; } } else { - if (server_port) { + if (server_port && priv->server_addr_v6) { server_port->min = priv->server_addr_v6->port; server_port->max = priv->server_addr_v6->port + priv->server_addr_v6->n_ports - 1; diff --git a/tests/check/gst/stream.c b/tests/check/gst/stream.c index 0447acc..979c0d6 100644 --- a/tests/check/gst/stream.c +++ b/tests/check/gst/stream.c @@ -385,6 +385,47 @@ GST_START_TEST (test_allocate_udp_ports_client_settings) GST_END_TEST; +GST_START_TEST (test_tcp_transport) +{ + GstPad *srcpad; + GstElement *pay; + GstRTSPStream *stream; + GstBin *bin; + GstElement *rtpbin; + GstRTSPRange server_port; + + srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC); + fail_unless (srcpad != NULL); + gst_pad_set_active (srcpad, TRUE); + pay = gst_element_factory_make ("rtpgstpay", "testpayloader"); + fail_unless (pay != NULL); + stream = gst_rtsp_stream_new (0, pay, srcpad); + fail_unless (stream != NULL); + gst_object_unref (pay); + gst_object_unref (srcpad); + rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin"); + fail_unless (rtpbin != NULL); + bin = GST_BIN (gst_bin_new ("testbin")); + fail_unless (bin != NULL); + fail_unless (gst_bin_add (bin, rtpbin)); + + /* TCP transport */ + gst_rtsp_stream_set_protocols (stream, GST_RTSP_LOWER_TRANS_TCP); + fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL)); + + /* port that the server will use to receive RTCP makes only sense in the UDP + * case so verify that the received server port is 0 in the TCP case */ + gst_rtsp_stream_get_server_port (stream, &server_port, G_SOCKET_FAMILY_IPV4); + fail_unless_equals_int (server_port.min, 0); + fail_unless_equals_int (server_port.max, 0); + + fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin)); + gst_object_unref (bin); + gst_object_unref (stream); +} + +GST_END_TEST; + static Suite * rtspstream_suite (void) { @@ -398,6 +439,7 @@ rtspstream_suite (void) tcase_add_test (tc, test_multicast_address_and_unicast_udp); tcase_add_test (tc, test_allocate_udp_ports_multicast); tcase_add_test (tc, test_allocate_udp_ports_client_settings); + tcase_add_test (tc, test_tcp_transport); return s; } |