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

Invalid Perl regex leads to misaligned access #244

Open
cmazakas opened this issue Feb 18, 2025 · 1 comment · May be fixed by #245
Open

Invalid Perl regex leads to misaligned access #244

cmazakas opened this issue Feb 18, 2025 · 1 comment · May be fixed by #245

Comments

@cmazakas
Copy link
Member

The following code:

int main()
{
   // char const strdata[] = "\x00t\x03.z%(?x:]*+\x0c#\\x0c\x0c\x0c+\x0c#\\x0c\x0c\x0c\x11\x0c\x0c\xff\xff\xfd*\xff\xff\xff\xff\xff\xff\xff\xff|\xff\xff\xfd*\xff\xff)*\x01\x03\x00\x00\x00\x03\xff\xff\xff\x00\x00\xff\xff\xff";
   char const strdata[] = "(?x:]*+#\x0c+)*";
   
   std::string str(strdata, strdata + sizeof(strdata) - 1);
   boost::regex e(str);
   std::string text = "hello, world!";

   boost::match_results<std::string::const_iterator> what;
   bool match = boost::regex_match(text, what, e,
                      boost::match_default | boost::match_partial);
   (void)match;
}

will cause the following runtime failure with ubsan:

boost/regex/v5/basic_regex_creator.hpp:717:21: runtime error: member access within misaligned address 0x51d0000001b7 for type 're_syntax_base', which requires 8 byte alignment
0x51d0000001b7: note: pointer points here
 00 00 01 be be  00 00 00 00 00 00 00 00  b7 01 00 00 d0 51 00 00  00 00 00 00 00 01 be be  00 00 00

We erroneously accept this regex. Perl fails with:

Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE ?x:]*+#\x0c+)*/ at test.pl line 3.

when given:

"rawr" =~ /(?x:]*+#\x0c+)*/
@cmazakas
Copy link
Member Author

@cmazakas cmazakas linked a pull request Feb 20, 2025 that will close this issue
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 a pull request may close this issue.

1 participant