Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regex constructor does not throw an exception for invalid backreferences in basic/grep patterns #33645

Closed
Quuxplusone opened this issue Aug 23, 2017 · 2 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@Quuxplusone
Copy link
Contributor

Bugzilla Link 34297
Resolution FIXED
Resolved on Feb 22, 2020 10:08
Version unspecified
OS All
CC @mordante,@mclow

Extended Description

#include
#include <stdio.h>

int main() {
std::regex rx("(cat)\1", std::regex::basic);
puts("Constructed without throwing: oops!");
try {
std::regex_match("(cat)", rx);
} catch (std::exception& e) {
puts("regex_match threw instead: oops!");
puts(e.what());
}
}

The output is:

Constructed without throwing: oops!
regex_match threw instead: oops!
The expression contained an invalid back reference.

I claim that the constructor should detect and throw on this pattern, rather than throwing at match time. The same issue happens with the "std::regex::grep" dialect, too.

@Quuxplusone
Copy link
Contributor Author

assigned to @mordante

@mordante
Copy link
Member

I had a look at this bug and while investigating I found another bug. Posted the following patches for review.

https://reviews.llvm.org/D62451
https://reviews.llvm.org/D62452
https://reviews.llvm.org/D62453

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants