This function is deprecated because it is lacking a length parameter, so
malformed UTF-8 may cause it to read beyond the buffer. This commit
causes it to not read beyond a NUL character, which makes it safe for
the common case that the input is a C string.
{
PERL_ARGS_ASSERT_IS_UTF8_CHAR;
- /* Assumes we have enough space, which is why this is deprecated */
- return isUTF8_CHAR(s, s + UTF8SKIP(s));
+ /* Assumes we have enough space, which is why this is deprecated. But the
+ * strnlen() makes it safe for the common case of NUL-terminated strings */
+ return isUTF8_CHAR(s, s + strnlen((char *) s, UTF8SKIP(s)));
}
/*