]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] ensure that entries in PersistentAutoDictionary are not empty
authorKostya Serebryany <kcc@google.com>
Thu, 19 Jan 2017 21:14:47 +0000 (21:14 +0000)
committerKostya Serebryany <kcc@google.com>
Thu, 19 Jan 2017 21:14:47 +0000 (21:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292520 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerMutate.cpp

index f059264db8aa6cf6d3d6b3950749b6fb751d9be0..9b019e9812fef94e29a7d4527c4b05605166cc88 100644 (file)
@@ -272,6 +272,7 @@ size_t MutationDispatcher::Mutate_AddWordFromTORC(
   default:
     assert(0);
   }
+  if (!DE.GetW().size()) return 0;
   Size = ApplyDictionaryEntry(Data, Size, MaxSize, DE);
   if (!Size) return 0;
   DictionaryEntry &DERef =
@@ -462,6 +463,7 @@ void MutationDispatcher::RecordSuccessfulMutationSequence() {
   for (auto DE : CurrentDictionaryEntrySequence) {
     // PersistentAutoDictionary.AddWithSuccessCountOne(DE);
     DE->IncSuccessCount();
+    assert(DE->GetW().size());
     // Linear search is fine here as this happens seldom.
     if (!PersistentAutoDictionary.ContainsWord(DE->GetW()))
       PersistentAutoDictionary.push_back({DE->GetW(), 1});
@@ -476,6 +478,7 @@ void MutationDispatcher::PrintRecommendedDictionary() {
   if (V.empty()) return;
   Printf("###### Recommended dictionary. ######\n");
   for (auto &DE: V) {
+    assert(DE.GetW().size());
     Printf("\"");
     PrintASCII(DE.GetW(), "\"");
     Printf(" # Uses: %zd\n", DE.GetUseCount());