[asan] report an error if blacklist file contains a malformed regex. fixes asan issue 17
authorKostya Serebryany <kcc@google.com>
Tue, 13 Dec 2011 19:34:53 +0000 (19:34 +0000)
committerKostya Serebryany <kcc@google.com>
Tue, 13 Dec 2011 19:34:53 +0000 (19:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146503 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/AddressSanitizer.cpp

index f16bdf530c528d485e9da85600aabab72d239946..f170cf150ab873fccabb3e1ddf381dba4d38a39a 100644 (file)
@@ -979,15 +979,23 @@ BlackList::BlackList(const std::string &Path) {
   for (size_t i = 0, numLines = Lines.size(); i < numLines; i++) {
     if (Lines[i].startswith(kFunPrefix)) {
       std::string ThisFunc = Lines[i].substr(strlen(kFunPrefix));
-      if (Fun.size()) {
-        Fun += "|";
-      }
+      std::string ThisFuncRE;
       // add ThisFunc replacing * with .*
       for (size_t j = 0, n = ThisFunc.size(); j < n; j++) {
         if (ThisFunc[j] == '*')
-          Fun += '.';
-        Fun += ThisFunc[j];
+          ThisFuncRE += '.';
+        ThisFuncRE += ThisFunc[j];
       }
+      // Check that the regexp is valid.
+      Regex CheckRE(ThisFuncRE);
+      std::string Error;
+      if (!CheckRE.isValid(Error))
+        report_fatal_error("malformed blacklist regex: " + ThisFunc +
+                           ": " + Error);
+      // Append to the final regexp.
+      if (Fun.size())
+        Fun += "|";
+      Fun += ThisFuncRE;
     }
   }
   if (Fun.size()) {