mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-03 19:36:16 +01:00
gutf8: Add ifunc resolver for g_str_is_ascii() too
Just like how commit ad572e7780
added an
ifunc resolver for `g_utf8_validate()`, we also need to add one for
`g_str_is_ascii()`, as it also calls into the c-utf8 SIMD validation
code which causes false-positive buffer read overflow warnings from
valgrind and asan.
I thought about just adding the `strlen()` call into `g_str_is_ascii()`
unconditionally, as a simpler fix, but from a quick
codesearch.debian.net, it appears `g_str_is_ascii()` is used quite
widely, so this would have an unacceptable performance impact.
This should fix the valgrind failures on the `search-utils` test seen
here: https://gitlab.gnome.org/GNOME/glib/-/jobs/4423753.
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
parent
1755024caf
commit
cf982177dd
43
glib/gutf8.c
43
glib/gutf8.c
@ -1969,6 +1969,38 @@ g_utf8_validate_len (const char *str,
|
|||||||
return max_len == 0;
|
return max_len == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
g_str_is_ascii_native (const char *str)
|
||||||
|
{
|
||||||
|
utf8_verify_ascii (&str, NULL);
|
||||||
|
|
||||||
|
return *str == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_WORKING_IFUNC_ATTRIBUTE
|
||||||
|
/* See above comment about `ifunc` use for g_utf8_validate(). */
|
||||||
|
static gboolean
|
||||||
|
g_str_is_ascii_valgrind (const char *str)
|
||||||
|
{
|
||||||
|
size_t len = strlen (str);
|
||||||
|
|
||||||
|
utf8_verify_ascii (&str, &len);
|
||||||
|
|
||||||
|
return *str == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef gboolean (*GStrIsAsciiFunc) (const char *str);
|
||||||
|
|
||||||
|
static GStrIsAsciiFunc
|
||||||
|
resolve_g_str_is_ascii (void)
|
||||||
|
{
|
||||||
|
if (RUNNING_ON_VALGRIND)
|
||||||
|
return g_str_is_ascii_valgrind;
|
||||||
|
else
|
||||||
|
return g_str_is_ascii_native;
|
||||||
|
}
|
||||||
|
#endif /* HAVE_WORKING_IFUNC_ATTRIBUTE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_str_is_ascii:
|
* g_str_is_ascii:
|
||||||
* @str: a string
|
* @str: a string
|
||||||
@ -1980,13 +2012,18 @@ g_utf8_validate_len (const char *str,
|
|||||||
*
|
*
|
||||||
* Since: 2.40
|
* Since: 2.40
|
||||||
*/
|
*/
|
||||||
|
#if g_macro__has_attribute(no_sanitize_address)
|
||||||
|
__attribute__((no_sanitize_address))
|
||||||
|
#endif
|
||||||
gboolean
|
gboolean
|
||||||
g_str_is_ascii (const gchar *str)
|
g_str_is_ascii (const gchar *str)
|
||||||
|
#ifdef HAVE_WORKING_IFUNC_ATTRIBUTE
|
||||||
|
__attribute__((ifunc ("resolve_g_str_is_ascii")));
|
||||||
|
#else
|
||||||
{
|
{
|
||||||
utf8_verify_ascii (&str, NULL);
|
return g_str_is_ascii_native (str);
|
||||||
|
|
||||||
return *str == 0;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_unichar_validate:
|
* g_unichar_validate:
|
||||||
|
Loading…
Reference in New Issue
Block a user