Skip to content

Commit e491e97

Browse files
k-takatanobu
authored andcommitted
[k-takata/Onigmo] Fix out-of-bounds read in parse_char_class()
(Close k-takata/Onigmo#139) /[\x{111111}]/ causes out-of-bounds read when encoding is a single byte encoding. \x{111111} is an invalid codepoint for a single byte encoding. Check if it is a valid codepoint. k-takata/Onigmo@d4cf99d30b
1 parent 6efedcf commit e491e97

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

regenc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,18 +640,23 @@ onigenc_single_byte_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED,
640640
}
641641

642642
extern int
643-
onigenc_single_byte_code_to_mbclen(OnigCodePoint code ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
643+
onigenc_single_byte_code_to_mbclen(OnigCodePoint code, OnigEncoding enc ARG_UNUSED)
644644
{
645+
if (code > 0xff)
646+
return ONIGERR_INVALID_CODE_POINT_VALUE;
645647
return 1;
646648
}
647649

648650
extern int
649651
onigenc_single_byte_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc ARG_UNUSED)
650652
{
653+
if (code > 0xff) {
651654
#ifdef RUBY
652-
if (code > 0xff)
653655
rb_raise(rb_eRangeError, "%u out of char range", code);
656+
#else
657+
return ONIGERR_INVALID_CODE_POINT_VALUE;
654658
#endif
659+
}
655660
*buf = (UChar )(code & 0xff);
656661
return 1;
657662
}

0 commit comments

Comments
 (0)