mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-29 15:26:18 +01:00
GVariant: Check for size == 0 in get_bytestring
And add a test from David that shows the problem. Closes #629698
This commit is contained in:
parent
2211ab1240
commit
235820d0ef
@ -1368,7 +1368,7 @@ g_variant_get_bytestring (GVariant *value)
|
|||||||
string = g_variant_get_data (value);
|
string = g_variant_get_data (value);
|
||||||
size = g_variant_get_size (value);
|
size = g_variant_get_size (value);
|
||||||
|
|
||||||
if (string[size - 1] == '\0')
|
if (size && string[size - 1] == '\0')
|
||||||
return string;
|
return string;
|
||||||
else
|
else
|
||||||
return "";
|
return "";
|
||||||
|
@ -3819,6 +3819,8 @@ test_bytestring (void)
|
|||||||
GVariant *value;
|
GVariant *value;
|
||||||
gchar **strv;
|
gchar **strv;
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
const gchar *const_str;
|
||||||
|
GVariant *untrusted_empty;
|
||||||
|
|
||||||
strv = g_strsplit (test_string, ",", 0);
|
strv = g_strsplit (test_string, ",", 0);
|
||||||
|
|
||||||
@ -3884,6 +3886,12 @@ test_bytestring (void)
|
|||||||
g_variant_get_child (value, 3, "^&ay", &str);
|
g_variant_get_child (value, 3, "^&ay", &str);
|
||||||
g_assert_cmpstr (str, ==, "foo");
|
g_assert_cmpstr (str, ==, "foo");
|
||||||
g_variant_unref (value);
|
g_variant_unref (value);
|
||||||
|
|
||||||
|
untrusted_empty = g_variant_new_from_data (G_VARIANT_TYPE ("ay"), NULL, 0, FALSE, NULL, NULL);
|
||||||
|
value = g_variant_get_normal_form (untrusted_empty);
|
||||||
|
const_str = g_variant_get_bytestring (value);
|
||||||
|
g_variant_unref (value);
|
||||||
|
g_variant_unref (untrusted_empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user