summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2016-12-15 20:11:00 -0700
committerKarl Williamson <khw@cpan.org>2016-12-23 22:36:34 -0700
commit042d9e5039128be63013ec1b4e120e4b3cebc48c (patch)
treee98680cb6b42de54f7d0216a3338175559b99e1c /locale.c
parentfa8ab37438503dde8c6e781d0d56daf54a633f6b (diff)
downloadperl-042d9e5039128be63013ec1b4e120e4b3cebc48c.tar.gz
Convert some calls to test for malformations
Code review showed several places in core where a UTF-8 sequence that was for a code point below 256 could be malformed, and be blindly accepted. Convert these to use the similar macro that does the check. One place in regexec.c was not converted because it is working on the pattern, which perl should have generated itself, so very unlikely to be bemalformed. I didn't add tests for these, as it would be a pain to figure out somehow to trigger them, and this is precautionary, based on code reading rather than any known field experience.
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/locale.c b/locale.c
index 07f599c032..b86077ffa4 100644
--- a/locale.c
+++ b/locale.c
@@ -1723,13 +1723,14 @@ Perl__mem_collxfrm(pTHX_ const char *input_string,
{
STRLEN i;
STRLEN d= 0;
+ char * e = (char *) t + len;
for (i = 0; i < len; i+= UTF8SKIP(t + i)) {
U8 cur_char = t[i];
if (UTF8_IS_INVARIANT(cur_char)) {
s[d++] = cur_char;
}
- else if (UTF8_IS_DOWNGRADEABLE_START(cur_char)) {
+ else if (UTF8_IS_NEXT_CHAR_DOWNGRADEABLE(t + i, e)) {
s[d++] = EIGHT_BIT_UTF8_TO_NATIVE(cur_char, t[i+1]);
}
else { /* Replace illegal cp with highest collating