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:
Ryan Lortie 2010-09-14 14:55:38 -04:00
parent 2211ab1240
commit 235820d0ef
2 changed files with 9 additions and 1 deletions

View File

@ -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 "";

View File

@ -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