[libcxx] r243030 - Detect and throw on a class of bad regexes that we mistakenly accepted before. Thanks to Trevor Smigiel for the report
Marshall Clow
mclow.lists at gmail.com
Thu Jul 23 11:27:52 PDT 2015
Author: marshall
Date: Thu Jul 23 13:27:51 2015
New Revision: 243030
URL: http://llvm.org/viewvc/llvm-project?rev=243030&view=rev
Log:
Detect and throw on a class of bad regexes that we mistakenly accepted before. Thanks to Trevor Smigiel for the report
Added:
libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp
Modified:
libcxx/trunk/include/regex
libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=243030&r1=243029&r2=243030&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Thu Jul 23 13:27:51 2015
@@ -4305,6 +4305,14 @@ basic_regex<_CharT, _Traits>::__parse_at
}
}
break;
+ case '*':
+ case '+':
+ case '?':
+ case '{':
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ throw regex_error(regex_constants::error_badrepeat);
+#endif
+ break;
default:
__first = __parse_pattern_character(__first, __last);
break;
Modified: libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp?rev=243030&r1=243029&r2=243030&view=diff
==============================================================================
--- libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp Thu Jul 23 13:27:51 2015
@@ -22,7 +22,7 @@ static bool error_escape_thrown(const ch
bool result = false;
try {
std::regex re(pat);
- } catch (std::regex_error &ex) {
+ } catch (const std::regex_error &ex) {
result = (ex.code() == std::regex_constants::error_escape);
}
return result;
Added: libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp?rev=243030&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp Thu Jul 23 13:27:51 2015
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT, class traits = regex_traits<charT>> class basic_regex;
+
+// template <class ST, class SA>
+// basic_regex(const basic_string<charT, ST, SA>& s);
+
+#include <regex>
+#include <cassert>
+
+static bool error_badrepeat_thrown(const char *pat)
+{
+ bool result = false;
+ try {
+ std::regex re(pat);
+ } catch (const std::regex_error &ex) {
+ result = (ex.code() == std::regex_constants::error_badrepeat);
+ }
+ return result;
+}
+
+int main()
+{
+ assert(error_badrepeat_thrown("?a"));
+ assert(error_badrepeat_thrown("*a"));
+ assert(error_badrepeat_thrown("+a"));
+ assert(error_badrepeat_thrown("{a"));
+
+ assert(error_badrepeat_thrown("?(a+)"));
+ assert(error_badrepeat_thrown("*(a+)"));
+ assert(error_badrepeat_thrown("+(a+)"));
+ assert(error_badrepeat_thrown("{(a+)"));
+}
More information about the cfe-commits
mailing list