mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 08:25:20 +08:00
Check the result of compile_length_tree() at every call site (#19505)
Two call sites added a negative error code into a jump offset instead of returning it. It was harmless since compilation fails later anyway. Reported-by: Owais Lone (thesecguy) <thesecguy45@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c2b6f7f0a7
commit
78a7f126f3
2 files changed
+15
-1
Notes:
git
2026-10-25 08:19:45 +00:00
Merged-By: makenowjust <make.just.on@gmail.com>
No files matched your search
@@ -1356,6 +1356,7 @@ compile_enclose_node(EncloseNode* node, regex_t* reg)
|
||||
r = add_abs_addr(reg, (int )node->call_addr);
|
||||
if (r) return r;
|
||||
len = compile_length_tree(node->target, reg);
|
||||
if (len < 0) return len;
|
||||
len += (SIZE_OP_MEMORY_START_PUSH + SIZE_OP_RETURN);
|
||||
if (BIT_STATUS_AT(reg->bt_mem_end, node->regnum))
|
||||
len += (IS_ENCLOSE_RECURSION(node)
|
||||
@@ -1604,6 +1605,7 @@ compile_anchor_node(AnchorNode* node, regex_t* reg)
|
||||
{
|
||||
int n;
|
||||
len = compile_length_tree(node->target, reg);
|
||||
if (len < 0) return ONIGERR_PARSER_BUG;
|
||||
r = add_opcode_rel_addr(reg, OP_PUSH_LOOK_BEHIND_NOT,
|
||||
len + SIZE_OP_FAIL_LOOK_BEHIND_NOT);
|
||||
if (r) return r;
|
||||
@@ -1742,7 +1744,9 @@ compile_tree(Node* node, regex_t* reg)
|
||||
Node* x = node;
|
||||
len = 0;
|
||||
do {
|
||||
len += compile_length_tree(NCAR(x), reg);
|
||||
r = compile_length_tree(NCAR(x), reg);
|
||||
if (r < 0) return r;
|
||||
len += r;
|
||||
if (NCDR(x) != NULL) {
|
||||
len += SIZE_OP_PUSH + SIZE_OP_JUMP;
|
||||
}
|
||||
@@ -1751,6 +1755,7 @@ compile_tree(Node* node, regex_t* reg)
|
||||
|
||||
do {
|
||||
len = compile_length_tree(NCAR(node), reg);
|
||||
if (len < 0) return ONIGERR_PARSER_BUG;
|
||||
if (IS_NOT_NULL(NCDR(node))) {
|
||||
r = add_opcode_rel_addr(reg, OP_PUSH, len + SIZE_OP_JUMP);
|
||||
if (r) break;
|
||||
|
||||
@@ -2035,6 +2035,15 @@ class TestRegexp < Test::Unit::TestCase
|
||||
end;
|
||||
end
|
||||
|
||||
def test_invalid_condition_in_alternation_and_call
|
||||
assert_raise_with_message(RegexpError, /invalid conditional pattern/) do
|
||||
Regexp.new("(x)|(?(1)x|x|)")
|
||||
end
|
||||
assert_raise_with_message(RegexpError, /invalid conditional pattern/) do
|
||||
Regexp.new("(?<b>x)(?<a>(?(<b>)x|x|))\\g<a>")
|
||||
end
|
||||
end
|
||||
|
||||
def test_too_big_number_for_repeat_range
|
||||
assert_raise_with_message(SyntaxError, /too big number for repeat range/) do
|
||||
eval(%[/|{1000000}/])
|
||||
|
||||
Reference in new issue
Block a user