[llvm] r257848 - [libFuzzer] use custom stol; also introduce __libfuzzer_is_present so that users can check for its presence.

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 14 16:17:37 PST 2016


Author: kcc
Date: Thu Jan 14 18:17:37 2016
New Revision: 257848

URL: http://llvm.org/viewvc/llvm-project?rev=257848&view=rev
Log:
[libFuzzer] use custom stol; also introduce __libfuzzer_is_present so that users can check for its presence.

Modified:
    llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp

Modified: llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp?rev=257848&r1=257847&r2=257848&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp Thu Jan 14 18:17:37 2016
@@ -23,6 +23,10 @@
 #include <algorithm>
 #include <iterator>
 
+// This function should be present in the libFuzzer so that the client
+// binary can test for its existence.
+extern "C" __attribute__((used)) void __libfuzzer_is_present() {}
+
 namespace fuzzer {
 
 // Program arguments.
@@ -93,6 +97,18 @@ static const char *FlagValue(const char
   return nullptr;
 }
 
+// Avoid calling stol as it triggers a bug in clang/glibc build.
+static long MyStol(const char *Str) {
+  long Res = 0;
+  for (size_t i = 0; Str[i]; i++) {
+    char Ch = Str[i];
+    if (Ch < '0' || Ch > '9')
+      return Res;
+    Res = Res * 10 + (Ch - '0');
+  }
+  return Res;
+}
+
 static bool ParseOneFlag(const char *Param) {
   if (Param[0] != '-') return false;
   if (Param[1] == '-') {
@@ -108,7 +124,7 @@ static bool ParseOneFlag(const char *Par
     const char *Str = FlagValue(Param, Name);
     if (Str)  {
       if (FlagDescriptions[F].IntFlag) {
-        int Val = std::stol(Str);
+        int Val = MyStol(Str);
         *FlagDescriptions[F].IntFlag = Val;
         if (Flags.verbosity >= 2)
           Printf("Flag: %s %d\n", Name, Val);;




More information about the llvm-commits mailing list