$OpenBSD: patch-boost_regex_v4_basic_regex_parser_hpp,v 1.1 2008/05/27 00:52:01 deanna Exp $
--- boost/regex/v4/basic_regex_parser.hpp.orig	Wed Dec 20 12:19:05 2006
+++ boost/regex/v4/basic_regex_parser.hpp	Sun May 25 21:59:07 2008
@@ -777,6 +777,7 @@ bool basic_regex_parser<charT, traits>::parse_repeat(s
       case syntax_element_restart_continue:
       case syntax_element_jump:
       case syntax_element_startmark:
+      case syntax_element_backstep:
          // can't legally repeat any of the above:
          fail(regex_constants::error_badrepeat, m_position - m_base);
          return false;
@@ -1862,6 +1863,7 @@ bool basic_regex_parser<charT, traits>::parse_perl_ext
    if(markid == -4)
    {
       re_syntax_base* b = this->getaddress(expected_alt_point);
+      // Make sure we have exactly one alternative following this state:
       if(b->type != syntax_element_alt)
       {
          re_alt* alt = static_cast<re_alt*>(this->insert_state(expected_alt_point, syntax_element_alt, sizeof(re_alt)));
@@ -1870,6 +1872,15 @@ bool basic_regex_parser<charT, traits>::parse_perl_ext
       else if(this->getaddress(static_cast<re_alt*>(b)->alt.i, b)->type == syntax_element_alt)
       {
          fail(regex_constants::error_bad_pattern, m_position - m_base);
+         return false;
+      }
+      // check for invalid repetition of next state:
+      b = this->getaddress(expected_alt_point);
+      b = this->getaddress(static_cast<re_alt*>(b)->next.i, b);
+      if((b->type != syntax_element_assert_backref)
+         && (b->type != syntax_element_startmark))
+      {
+         fail(regex_constants::error_badrepeat, m_position - m_base);
          return false;
       }
    }
