Skip to content

Commit

Permalink
Detect the premature end of char property in regexp
Browse files Browse the repository at this point in the history
Default to ONIGERR_INVALID_CHAR_PROPERTY_NAME in
fetch_char_property_to_ctype and only set otherwise if an ending
} is found.

Fixes [Bug #17340]
  • Loading branch information
jeremyevans authored and eregon committed Nov 24, 2020
1 parent 237cb94 commit b26d6c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions regparse.c
Expand Up @@ -4348,7 +4348,7 @@ fetch_char_property_to_ctype(UChar** src, UChar* end, ScanEnv* env)
OnigEncoding enc = env->enc;
UChar *prev, *start, *p = *src;

r = 0;
r = ONIGERR_INVALID_CHAR_PROPERTY_NAME;
start = prev = p;

while (!PEND) {
Expand All @@ -4362,7 +4362,6 @@ fetch_char_property_to_ctype(UChar** src, UChar* end, ScanEnv* env)
return r;
}
else if (c == '(' || c == ')' || c == '{' || c == '|') {
r = ONIGERR_INVALID_CHAR_PROPERTY_NAME;
break;
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/ruby/test_regexp.rb
Expand Up @@ -57,6 +57,17 @@ def test_ruby_dev_31309
assert_equal('Ruby', 'Ruby'.sub(/[^a-z]/i, '-'))
end

def test_premature_end_char_property
["\\p{",
"\\p{".dup.force_encoding("UTF-8"),
"\\p{".dup.force_encoding("US-ASCII")
].each do |string|
assert_raise(RegexpError) do
Regexp.new(string)
end
end
end

def test_assert_normal_exit
# moved from knownbug. It caused core.
Regexp.union("a", "a")
Expand Down

0 comments on commit b26d6c7

Please sign in to comment.