webrtcstats: Fix null pointer dereference
authorPhilippe Normand <philn@igalia.com>
Wed, 29 Dec 2021 15:02:03 +0000 (15:02 +0000)
committerPhilippe Normand <philn@igalia.com>
Wed, 29 Dec 2021 15:55:57 +0000 (15:55 +0000)
If there is no jitterbuffer stats we should not attempt to store them in the
global stats structure.

Also add a g_return_if_fail in _gst_structure_take_structure() about this
because it is a programmer error to pass an invalid pointer address there.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1479>

subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcstats.c

index 04261c5..3d31b4a 100644 (file)
@@ -89,6 +89,8 @@ _gst_structure_take_structure (GstStructure * s, const char *fieldname,
 {
   GValue v = G_VALUE_INIT;
 
+  g_return_if_fail (GST_IS_STRUCTURE (*value_s));
+
   g_value_init (&v, GST_TYPE_STRUCTURE);
   g_value_take_boxed (&v, *value_s);
 
@@ -543,7 +545,9 @@ _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc,
     /* Store the raw stats from GStreamer into the structure for advanced
      * information.
      */
-    _gst_structure_take_structure (in, "gst-rtpjitterbuffer-stats", &jb_stats);
+    if (jb_stats)
+      _gst_structure_take_structure (in, "gst-rtpjitterbuffer-stats",
+          &jb_stats);
 
     gst_structure_set (in, "gst-rtpsource-stats", GST_TYPE_STRUCTURE,
         source_stats, NULL);