Patchwork [v3] libstdc++/47724 prevent crash compiling a regex

login
register
mail settings
Submitter Jonathan Wakely
Date Feb. 17, 2011, 1:52 a.m.
Message ID <AANLkTikGW5dC_E8zb7GKkkxf5mDvXfoygceKBi5b=ym1@mail.gmail.com>
Download mbox | patch
Permalink /patch/83421/
State New
Headers show

Comments

Jonathan Wakely - Feb. 17, 2011, 1:52 a.m.
This "fixes" PR 47724 by treating ^ and $ as non-metacharacters.
Unless someone has time to properly implement line anchors in <regex>
then this may be the best we can do for 4.6.0

2011-02-17  Jonathan Wakely  <jwakely.gcc@gmail.com>

        PR libstdc++/47724
        * include/bits/regex_compiler.h (_Scanner::_M_advance): Do not treat
        line anchors as metacharacters.
        * testsuite/28_regex/basic_regex/ctors/47724.cc: New.

tested x86_64-linux, committed to trunk.

Patch

Index: include/bits/regex_compiler.h
===================================================================
--- include/bits/regex_compiler.h	(revision 170158)
+++ include/bits/regex_compiler.h	(working copy)
@@ -171,6 +171,9 @@  namespace __regex
 	  _M_scan_in_brace();
 	  return;
 	}
+#if 0
+      // TODO: re-enable line anchors when _M_assertion is implemented.
+      // See PR libstdc++/47724
       else if (_M_state & _S_state_at_start && __c == _M_ctype.widen('^'))
 	{
 	  _M_curToken = _S_token_line_begin;
@@ -183,6 +186,7 @@  namespace __regex
 	  ++_M_current;
 	  return;
 	}
+#endif
       else if (__c == _M_ctype.widen('.'))
 	{
 	  _M_curToken = _S_token_anychar;
Index: testsuite/28_regex/basic_regex/ctors/47724.cc
===================================================================
--- testsuite/28_regex/basic_regex/ctors/47724.cc	(revision 0)
+++ testsuite/28_regex/basic_regex/ctors/47724.cc	(revision 0)
@@ -0,0 +1,34 @@ 
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// PR libstdc++/47724
+
+#include <regex>
+
+void test01()
+{
+  std::regex s("^$");
+}
+
+int
+main()
+{ 
+  test01();
+  return 0;
+};