Skip to content

re2: fix null pointer dereference in Set::Compile() failure path#636

Open
rui-wang-8 wants to merge 1 commit into
google:mainfrom
rui-wang-8:fix-set-compile-null-deref
Open

re2: fix null pointer dereference in Set::Compile() failure path#636
rui-wang-8 wants to merge 1 commit into
google:mainfrom
rui-wang-8:fix-set-compile-null-deref

Conversation

@rui-wang-8
Copy link
Copy Markdown

When Prog::CompileSet() returns nullptr (e.g., DFA memory
exhaustion), the internal state of Set becomes inconsistent:
compiled_ is already set to true but prog_ is nullptr.
A subsequent call to Set::Match() passes the !compiled_ check
and dereferences the null prog_.

Fix: set compiled_ based on whether compilation actually succeeded,
rather than unconditionally before it. Similarly, defer elem_.clear()
so that state remains valid for retry on failure.

This restores the invariant: compiled_ implies prog_ != nullptr.

Also add a regression test using max_mem(1) to guarantee
compilation failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant