mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
collate: Don't segfault on bad input
This commit is contained in:
parent
e67a36c479
commit
81ec27c33b
@ -401,6 +401,8 @@ g_utf8_collate_key (const gchar *str,
|
|||||||
|
|
||||||
str_norm = _g_utf8_normalize_wc (str, len, G_NORMALIZE_ALL_COMPOSE);
|
str_norm = _g_utf8_normalize_wc (str, len, G_NORMALIZE_ALL_COMPOSE);
|
||||||
|
|
||||||
|
g_return_val_if_fail (str_norm != NULL, NULL);
|
||||||
|
|
||||||
xfrm_len = wcsxfrm (NULL, (wchar_t *)str_norm, 0);
|
xfrm_len = wcsxfrm (NULL, (wchar_t *)str_norm, 0);
|
||||||
result_wc = g_new (wchar_t, xfrm_len + 1);
|
result_wc = g_new (wchar_t, xfrm_len + 1);
|
||||||
wcsxfrm (result_wc, (wchar_t *)str_norm, xfrm_len + 1);
|
wcsxfrm (result_wc, (wchar_t *)str_norm, xfrm_len + 1);
|
||||||
|
@ -182,6 +182,19 @@ test_unicode_normalize_invalid (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_unicode_normalize_bad_length (void)
|
||||||
|
{
|
||||||
|
const char *input = "fórmula, vol. 2 (deluxe edition)";
|
||||||
|
gsize len = 2;
|
||||||
|
char *output;
|
||||||
|
|
||||||
|
output = g_utf8_normalize (input, len, G_NORMALIZE_ALL_COMPOSE);
|
||||||
|
g_assert_null (output);
|
||||||
|
|
||||||
|
g_free (output);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -190,6 +203,7 @@ main (int argc, char **argv)
|
|||||||
g_test_add_func ("/unicode/normalize", test_unicode_normalize);
|
g_test_add_func ("/unicode/normalize", test_unicode_normalize);
|
||||||
g_test_add_func ("/unicode/normalize-invalid",
|
g_test_add_func ("/unicode/normalize-invalid",
|
||||||
test_unicode_normalize_invalid);
|
test_unicode_normalize_invalid);
|
||||||
|
g_test_add_func ("/unicode/normalize/bad-length", test_unicode_normalize_bad_length);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user