Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mrbgems/mruby-regexp/src/re_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class_add_shorthand(re_charclass *cc, int ch)
Returns FALSE for an unknown name. Semantics are ASCII, like this gem's
\w/\d shorthands; non-ASCII codepoints are not classified. */
static mrb_bool
posix_class_bits(uint8_t *bits, const char *name, uint16_t len)
posix_class_bits(uint8_t *bits, const char *name, size_t len)
{
#define NAME_IS(s) (len == sizeof(s) - 1 && memcmp(name, s, len) == 0)
#define BSET(ch) (bits[(ch) >> 3] |= (uint8_t)(1u << ((ch) & 7)))
Expand Down Expand Up @@ -409,7 +409,7 @@ compile_charclass(re_compiler *c)
while (peek(c) >= 0 && peek(c) != ':' && peek(c) != ']') next_char(c);
if (peek(c) == ':' && c->p + 1 < c->src_end && c->p[1] == ']') {
uint8_t bits[16] = {0};
if (!posix_class_bits(bits, name, (uint16_t)(c->p - name))) {
if (!posix_class_bits(bits, name, (size_t)(c->p - name))) {
compile_error(c, "invalid POSIX bracket class");
}
next_char(c); /* ':' */
Expand Down
6 changes: 6 additions & 0 deletions mrbgems/mruby-regexp/test/regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@
assert_equal "x", " x".match(/[^[:space:]]/)[0]
# an unknown class name is an error
assert_raise(RegexpError) { Regexp.new("[[:bogus:]]") }
# The name length used to be truncated with a (uint16_t) cast, so a name
# 65536 bytes longer than "alpha" compared equal to "alpha" and compiled
# as [[:alpha:]] instead of raising.
long = "alpha" + "A" * 65536
assert_raise(RegexpError) { Regexp.new("[[:#{long}:]]") }
assert_raise(RegexpError) { Regexp.new("[[:^#{long}:]]") }
end

assert("Regexp - \\b inside character class is backspace") do
Expand Down
Loading