GVariant parser: turn two asserts into soft errors
authorRyan Lortie <desrt@desrt.ca>
Wed, 17 Apr 2013 16:08:00 +0000 (12:08 -0400)
committerRyan Lortie <desrt@desrt.ca>
Fri, 19 Apr 2013 15:40:04 +0000 (11:40 -0400)
Parsing wrongly-typed GVariant text format data is a well-defined
operation and it ought to result in a GError.  We do that for most
cases, but 'v' and 'ay' were being treated differently.  Fix those as
well.

glib/gvariant-parser.c

index d5c036a..1421a34 100644 (file)
@@ -1142,7 +1142,9 @@ variant_get_value (AST                 *ast,
   Variant *variant = (Variant *) ast;
   GVariant *child;
 
-  g_assert (g_variant_type_equal (type, G_VARIANT_TYPE_VARIANT));
+  if (!g_variant_type_equal (type, G_VARIANT_TYPE_VARIANT))
+    return ast_type_error (ast, type, error);
+
   child = ast_resolve (variant->value, error);
 
   if (child == NULL)
@@ -1656,7 +1658,8 @@ bytestring_get_value (AST                 *ast,
 {
   ByteString *string = (ByteString *) ast;
 
-  g_assert (g_variant_type_equal (type, G_VARIANT_TYPE_BYTESTRING));
+  if (!g_variant_type_equal (type, G_VARIANT_TYPE_BYTESTRING))
+    return ast_type_error (ast, type, error);
 
   return g_variant_new_bytestring (string->string);
 }