value: fail flag deserialization on invalid flag names

This commit is contained in:
Tim-Philipp Müller 2016-01-18 19:17:16 +00:00
parent fb4b673c76
commit eb4c5498b5
2 changed files with 16 additions and 3 deletions

View 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);

View 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;