mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 07:26:15 +01:00
Merge branch 'backport-1788-ossfuzz-28458-date-overflow' into 'glib-2-66'
Backport !1788 “gdate: Validate input as UTF-8 before parsing” to glib-2-66 See merge request GNOME/glib!1790
This commit is contained in:
commit
2c25fe26c8
@ -1234,7 +1234,11 @@ g_date_set_parse (GDate *d,
|
|||||||
|
|
||||||
/* set invalid */
|
/* set invalid */
|
||||||
g_date_clear (d, 1);
|
g_date_clear (d, 1);
|
||||||
|
|
||||||
|
/* The input has to be valid UTF-8. */
|
||||||
|
if (!g_utf8_validate (str, -1, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
G_LOCK (g_date_global);
|
G_LOCK (g_date_global);
|
||||||
|
|
||||||
g_date_prepare_to_parse (str, &pt);
|
g_date_prepare_to_parse (str, &pt);
|
||||||
|
@ -184,6 +184,29 @@ test_parse (void)
|
|||||||
g_date_free (d);
|
g_date_free (d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_parse_invalid (void)
|
||||||
|
{
|
||||||
|
const gchar * const strs[] =
|
||||||
|
{
|
||||||
|
/* Incomplete UTF-8 sequence */
|
||||||
|
"\xfd",
|
||||||
|
};
|
||||||
|
gsize i;
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (strs); i++)
|
||||||
|
{
|
||||||
|
GDate *d = g_date_new ();
|
||||||
|
|
||||||
|
g_test_message ("Test %" G_GSIZE_FORMAT, i);
|
||||||
|
g_date_set_parse (d, strs[i]);
|
||||||
|
|
||||||
|
g_assert_false (g_date_valid (d));
|
||||||
|
|
||||||
|
g_date_free (d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_parse_locale_change (void)
|
test_parse_locale_change (void)
|
||||||
{
|
{
|
||||||
@ -770,6 +793,7 @@ main (int argc, char** argv)
|
|||||||
g_test_add_func ("/date/julian", test_julian_constructor);
|
g_test_add_func ("/date/julian", test_julian_constructor);
|
||||||
g_test_add_func ("/date/dates", test_dates);
|
g_test_add_func ("/date/dates", test_dates);
|
||||||
g_test_add_func ("/date/parse", test_parse);
|
g_test_add_func ("/date/parse", test_parse);
|
||||||
|
g_test_add_func ("/date/parse/invalid", test_parse_invalid);
|
||||||
g_test_add_func ("/date/parse_locale_change", test_parse_locale_change);
|
g_test_add_func ("/date/parse_locale_change", test_parse_locale_change);
|
||||||
g_test_add_func ("/date/month_substring", test_month_substring);
|
g_test_add_func ("/date/month_substring", test_month_substring);
|
||||||
g_test_add_func ("/date/month_names", test_month_names);
|
g_test_add_func ("/date/month_names", test_month_names);
|
||||||
|
Loading…
Reference in New Issue
Block a user