[PATCH] D40376: [LibFuzzer] Fix `CounterToFeature()` so that it doesn't ignore the 6th bit.

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 22 15:53:14 PST 2017


delcypher created this revision.

**WARNING: NOT TESTED**

The implementation of `CounterToFeature()` appeared to be wrong. It ignored the value of the 6th bit (i.e. the bit with value 64) and treated the input values of "3" specially.

If this is intentional then it presents a problem because this function is also used to handle user provided counters read from `__start___libfuzzer_extra_counters` to `__stop___libfuzzer_extra_counters`. In this case the previous implementation of `CounterToFeature()` meant that the counters can't be treated like a bitset (i.e. one feature per bit) because the 6th bit was ignored.

This patch is more of a drive-by observation that resulted from me trying to understand how to use user-provided counters. I suspect it will need revision as this function is used by more than just the user-provided counters. It also has not been tested in anyway because my machine is not setup for building LLVM right at this moment.


https://reviews.llvm.org/D40376

Files:
  lib/fuzzer/FuzzerTracePC.h


Index: lib/fuzzer/FuzzerTracePC.h
===================================================================
--- lib/fuzzer/FuzzerTracePC.h
+++ lib/fuzzer/FuzzerTracePC.h
@@ -202,11 +202,11 @@
     assert(Counter);
     unsigned Bit = 0;
     /**/ if (Counter >= 128) Bit = 7;
-    else if (Counter >= 32) Bit = 6;
-    else if (Counter >= 16) Bit = 5;
-    else if (Counter >= 8) Bit = 4;
-    else if (Counter >= 4) Bit = 3;
-    else if (Counter >= 3) Bit = 2;
+    else if (Counter >= 64) Bit = 6;
+    else if (Counter >= 32) Bit = 5;
+    else if (Counter >= 16) Bit = 4;
+    else if (Counter >= 8) Bit = 3;
+    else if (Counter >= 4) Bit = 2;
     else if (Counter >= 2) Bit = 1;
     return Bit;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40376.124016.patch
Type: text/x-patch
Size: 702 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171122/0bb775c1/attachment.bin>


More information about the llvm-commits mailing list