diff options
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerTracePC.cpp | 9 | ||||
| -rw-r--r-- | compiler-rt/test/fuzzer/SingleMemcmpTest.cpp | 3 |
2 files changed, 9 insertions, 3 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp index a2d3b7e7faf..4a1308de550 100644 --- a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp @@ -369,11 +369,16 @@ void TracePC::AddValueForMemcmp(void *caller_pc, const void *s1, const void *s2, Hash ^= (T << 8) | B2[i]; } size_t I = 0; - for (; I < Len; I++) - if (B1[I] != B2[I] || (StopAtZero && B1[I] == 0)) + uint8_t HammingDistance = 0; + for (; I < Len; I++) { + if (B1[I] != B2[I] || (StopAtZero && B1[I] == 0)) { + HammingDistance = Popcountll(B1[I] ^ B2[I]); break; + } + } size_t PC = reinterpret_cast<size_t>(caller_pc); size_t Idx = (PC & 4095) | (I << 12); + Idx += HammingDistance; ValueProfileMap.AddValue(Idx); TORCW.Insert(Idx ^ Hash, Word(B1, Len), Word(B2, Len)); } diff --git a/compiler-rt/test/fuzzer/SingleMemcmpTest.cpp b/compiler-rt/test/fuzzer/SingleMemcmpTest.cpp index ef0a89b806d..bd6b500f72d 100644 --- a/compiler-rt/test/fuzzer/SingleMemcmpTest.cpp +++ b/compiler-rt/test/fuzzer/SingleMemcmpTest.cpp @@ -10,7 +10,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { const char *S = (const char*)Data; - if (Size >= 6 && !memcmp(S, "qwerty", 6)) { + const char *Needle = "Some long string"; + if (Size >= strlen(Needle) && !memcmp(S, Needle, strlen(Needle))) { fprintf(stderr, "BINGO\n"); exit(1); } |

