value: fail flag deserialization on invalid flag names
authorTim-Philipp Müller <tim@centricular.com>
Mon, 18 Jan 2016 19:17:16 +0000 (19:17 +0000)
committerTim-Philipp Müller <tim@centricular.com>
Mon, 18 Jan 2016 19:39:11 +0000 (19:39 +0000)
gst/gstvalue.c
tests/check/gst/gstvalue.c

index f876be0..f3ada1e 100644 (file)
@@ -3235,7 +3235,6 @@ gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
   const gchar *pos = NULL;
   const gchar *next;
   gchar *cur_str, *endptr;
-
   guint flags = 0;
   guint mask = 0;
   guint val;
@@ -3273,8 +3272,10 @@ gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
     else {
       val = strtoul (cur_str, &endptr, 0);
       /* direct numeric value */
-      if (endptr == NULL || *endptr != '\0')
-        val = 0;                /* Invalid numeric, ignore it */
+      if (endptr == NULL || *endptr != '\0') {
+        g_free (cur_str);
+        return FALSE;           /* Invalid numeric or string we can't convert */
+      }
     }
     g_free (cur_str);
 
index fc04a00..7bb8955 100644 (file)
@@ -453,6 +453,8 @@ GST_START_TEST (test_deserialize_flags)
     "0",
     "GST_SEEK_FLAG_NONE",
     "GST_SEEK_FLAG_FLUSH",
+    "0xf",
+    "15",
     "GST_SEEK_FLAG_FLUSH+GST_SEEK_FLAG_ACCURATE",
   };
   GstSeekFlags results[] = {
@@ -460,6 +462,8 @@ GST_START_TEST (test_deserialize_flags)
     GST_SEEK_FLAG_NONE,
     GST_SEEK_FLAG_NONE,
     GST_SEEK_FLAG_FLUSH,
+    0xf,
+    15,
     GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
   };
   int i;
@@ -473,6 +477,14 @@ GST_START_TEST (test_deserialize_flags)
         "resulting value is %d, not %d, for string %s (%d)",
         g_value_get_flags (&value), results[i], strings[i], i);
   }
+
+  fail_if (gst_value_deserialize (&value, "foo"),
+      "flag deserializing for bogus value should have failed!");
+  fail_if (gst_value_deserialize (&value, "GST_SEEK_FLAG_FLUSH+foo"),
+      "flag deserializing for bogus value should have failed!");
+  fail_if (gst_value_deserialize (&value,
+          "GST_SEEK_FLAG_FLUSH+foo+GST_SEEK_FLAG_ACCURATE"),
+      "flag deserializing for bogus value should have failed!");
 }
 
 GST_END_TEST;