From 65e0907798aa99df6b70b0cecd351033f834ea08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 17 Apr 2018 11:01:09 +0100 Subject: [PATCH] inputselector, outputselector: add guards for wrong pads being set as active pads Catch users wrongly setting foreign pads or wrong pads as the selector's active pad, which leads to all kinds of other issues. It's a programming error so handle it just like we would if we had direct API. https://bugzilla.gnome.org/show_bug.cgi?id=795309 --- plugins/elements/gstinputselector.c | 8 ++++++++ plugins/elements/gstoutputselector.c | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/plugins/elements/gstinputselector.c b/plugins/elements/gstinputselector.c index f3f95e6833..e5514b0f29 100644 --- a/plugins/elements/gstinputselector.c +++ b/plugins/elements/gstinputselector.c @@ -1365,6 +1365,14 @@ gst_input_selector_set_active_pad (GstInputSelector * self, GstPad * pad) if (pad == self->active_sinkpad) return FALSE; + /* guard against users setting a src pad or foreign pad as active pad */ + if (pad != NULL) { + g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE); + g_return_val_if_fail (GST_IS_SELECTOR_PAD (pad), FALSE); + g_return_val_if_fail (GST_PAD_PARENT (pad) == GST_ELEMENT_CAST (self), + FALSE); + } + old = GST_SELECTOR_PAD_CAST (self->active_sinkpad); new = GST_SELECTOR_PAD_CAST (pad); diff --git a/plugins/elements/gstoutputselector.c b/plugins/elements/gstoutputselector.c index 03cf206211..2b97b98419 100644 --- a/plugins/elements/gstoutputselector.c +++ b/plugins/elements/gstoutputselector.c @@ -219,6 +219,12 @@ gst_output_selector_set_property (GObject * object, guint prop_id, GST_INFO_OBJECT (sel, "Activating pad %s:%s", GST_DEBUG_PAD_NAME (next_pad)); + /* guard against users setting a sink pad or foreign pad as active pad */ + if (next_pad != NULL) { + g_return_if_fail (GST_PAD_IS_SRC (next_pad)); + g_return_if_fail (GST_PAD_PARENT (next_pad) == GST_ELEMENT_CAST (sel)); + } + GST_OBJECT_LOCK (object); if (next_pad != sel->active_srcpad) { /* switch to new srcpad in next chain run */