[libFuzzer] support -runs=N in the fork mode. Make sure we see one-line reports from ubsan in the fork mode. Test both

llvm-svn: 358306
GitOrigin-RevId: 65132e2118140200dc57e2df9d8713dd07e72119
diff --git a/FuzzerFork.cpp b/FuzzerFork.cpp
index 52a233f..20c9950 100644
--- a/FuzzerFork.cpp
+++ b/FuzzerFork.cpp
@@ -103,6 +103,7 @@
   FuzzJob *CreateNewJob(size_t JobId) {
     Command Cmd(Args);
     Cmd.removeFlag("fork");
+    Cmd.removeFlag("runs");
     for (auto &C : CorpusDirs) // Remove all corpora from the args.
       Cmd.removeArgument(C);
     Cmd.addFlag("reload", "0");  // working in an isolated dir, no reload.
@@ -278,7 +279,8 @@
         std::ifstream In(Job->LogPath);
         std::string Line;
         while (std::getline(In, Line, '\n'))
-          if (Line.find("ERROR:") != Line.npos)
+          if (Line.find("ERROR:") != Line.npos ||
+              Line.find("runtime error:") != Line.npos)
             Printf("%s\n", Line.c_str());
       } else {
         // And exit if we don't ignore this crash.
@@ -298,6 +300,12 @@
              Env.secondsSinceProcessStartUp());
       Stop = true;
     }
+    if (Options.MaxNumberOfRuns >= 0 && !Stop &&
+        Env.NumRuns >= Options.MaxNumberOfRuns) {
+      Printf("INFO: fuzzed for %zd iterations, wrapping up soon\n",
+             Env.NumRuns);
+      Stop = true;
+    }
 
     if (!Stop)
       FuzzQ.Push(Env.CreateNewJob(JobId++));