summaryrefslogtreecommitdiff
path: root/mathoms.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2018-07-24 21:41:41 -0600
committerKarl Williamson <khw@cpan.org>2018-08-03 13:13:24 -0600
commitc6734c35eefe26067112bce2d763f16bc9d99333 (patch)
tree308d0e7f5e1cbe087e8b00e674adf0179aac3614 /mathoms.c
parent6f7ce6e80d292b2714db601b64fbbee35c5f181a (diff)
downloadperl-c6734c35eefe26067112bce2d763f16bc9d99333.tar.gz
mathoms.c: Make safer a deprecated function
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.
Diffstat (limited to 'mathoms.c')
-rw-r--r--mathoms.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/mathoms.c b/mathoms.c
index ed466c2c71..59d8aeacf7 100644
--- a/mathoms.c
+++ b/mathoms.c
@@ -1660,8 +1660,9 @@ Perl_is_utf8_char(const U8 *s)
{
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)));
}
/*