inputselector, outputselector: add guards for wrong pads being set as active pads
authorTim-Philipp Müller <tim@centricular.com>
Tue, 17 Apr 2018 10:01:09 +0000 (11:01 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Tue, 17 Apr 2018 17:57:17 +0000 (18:57 +0100)
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
plugins/elements/gstoutputselector.c

index f3f95e6..e5514b0 100644 (file)
@@ -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);
 
index 03cf206..2b97b98 100644 (file)
@@ -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 */