Patchwork D7370: fuzz: clean out most of fuzzutil

login
register
mail settings
Submitter phabricator
Date Nov. 12, 2019, 3:03 a.m.
Message ID <38be599f808c229ff0206530cf2d8e28@localhost.localdomain>
Download mbox | patch
Permalink /patch/43141/
State Not Applicable
Headers show

Comments

phabricator - Nov. 12, 2019, 3:03 a.m.
Closed by commit rHG6f5c352f41b6: fuzz: clean out most of fuzzutil (authored by durin42).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7370?vs=18030&id=18037

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7370/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7370

AFFECTED FILES
  contrib/fuzz/Makefile
  contrib/fuzz/fuzzutil.cc
  contrib/fuzz/fuzzutil.h

CHANGE DETAILS




To: durin42, #hg-reviewers, indygreg
Cc: mercurial-devel

Patch

diff --git a/contrib/fuzz/fuzzutil.h b/contrib/fuzz/fuzzutil.h
--- a/contrib/fuzz/fuzzutil.h
+++ b/contrib/fuzz/fuzzutil.h
@@ -34,14 +34,4 @@ 
 	if (level <= DEBUG)                                                    \
 	std::cout
 
-struct two_inputs {
-	std::unique_ptr<char[]> right;
-	size_t right_size;
-	std::unique_ptr<char[]> left;
-	size_t left_size;
-};
-
-/* Split a non-zero-length input into two inputs. */
-contrib::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size);
-
 #endif /* CONTRIB_FUZZ_FUZZUTIL_H */
diff --git a/contrib/fuzz/fuzzutil.cc b/contrib/fuzz/fuzzutil.cc
deleted file mode 100644
--- a/contrib/fuzz/fuzzutil.cc
+++ /dev/null
@@ -1,27 +0,0 @@ 
-#include "fuzzutil.h"
-
-#include <cstring>
-#include <utility>
-
-contrib::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size)
-{
-	if (!Size) {
-		return contrib::nullopt;
-	}
-	// figure out a random point in [0, Size] to split our input.
-	size_t left_size = (Data[0] / 255.0) * (Size - 1);
-
-	// Copy inputs to new allocations so if bdiff over-reads
-	// AddressSanitizer can detect it.
-	std::unique_ptr<char[]> left(new char[left_size]);
-	std::memcpy(left.get(), Data + 1, left_size);
-	// right starts at the next byte after left ends
-	size_t right_size = Size - (left_size + 1);
-	std::unique_ptr<char[]> right(new char[right_size]);
-	std::memcpy(right.get(), Data + 1 + left_size, right_size);
-	LOG(2) << "inputs are  " << left_size << " and " << right_size
-	       << " bytes" << std::endl;
-	two_inputs result = {std::move(right), right_size, std::move(left),
-	                     left_size};
-	return result;
-}
diff --git a/contrib/fuzz/Makefile b/contrib/fuzz/Makefile
--- a/contrib/fuzz/Makefile
+++ b/contrib/fuzz/Makefile
@@ -3,15 +3,6 @@ 
 
 all: bdiff mpatch xdiff
 
-fuzzutil.o: fuzzutil.cc fuzzutil.h
-	$(CXX) $(CXXFLAGS) -g -O1 \
-	  -std=c++17 \
-	  -I../../mercurial -c -o fuzzutil.o fuzzutil.cc
-
-fuzzutil-oss-fuzz.o: fuzzutil.cc fuzzutil.h
-	$(CXX) $(CXXFLAGS) -std=c++17 \
-	  -I../../mercurial -c -o fuzzutil-oss-fuzz.o fuzzutil.cc
-
 pyutil.o: pyutil.cc pyutil.h
 	$(CXX) $(CXXFLAGS) -g -O1 \
 	  `$$OUT/sanpy/bin/python-config --cflags` \
@@ -21,17 +12,17 @@ 
 	$(CC) $(CFLAGS) -fsanitize=fuzzer-no-link,address -c -o bdiff.o \
 	  ../../mercurial/bdiff.c
 
-bdiff: bdiff.cc bdiff.o fuzzutil.o
+bdiff: bdiff.cc bdiff.o 
 	$(CXX) $(CXXFLAGS) -DHG_FUZZER_INCLUDE_MAIN=1 -g -O1 -fsanitize=fuzzer-no-link,address \
 	  -std=c++17 \
-	  -I../../mercurial bdiff.cc bdiff.o fuzzutil.o -o bdiff
+	  -I../../mercurial bdiff.cc bdiff.o -o bdiff
 
 bdiff-oss-fuzz.o: ../../mercurial/bdiff.c
 	$(CC) $(CFLAGS) -c -o bdiff-oss-fuzz.o ../../mercurial/bdiff.c
 
-bdiff_fuzzer: bdiff.cc bdiff-oss-fuzz.o fuzzutil-oss-fuzz.o
+bdiff_fuzzer: bdiff.cc bdiff-oss-fuzz.o
 	$(CXX) $(CXXFLAGS) -std=c++17 -I../../mercurial bdiff.cc \
-	  bdiff-oss-fuzz.o fuzzutil-oss-fuzz.o -lFuzzingEngine -o \
+	  bdiff-oss-fuzz.o -lFuzzingEngine -o \
 	  $$OUT/bdiff_fuzzer
 
 mpatch.o: ../../mercurial/mpatch.c
@@ -39,16 +30,16 @@ 
 	  ../../mercurial/mpatch.c
 
 mpatch: CXXFLAGS += -std=c++17
-mpatch: mpatch.cc mpatch.o fuzzutil.o
+mpatch: mpatch.cc mpatch.o
 	$(CXX) $(CXXFLAGS) -DHG_FUZZER_INCLUDE_MAIN=1 -g -O1 -fsanitize=fuzzer-no-link,address \
-	  -I../../mercurial mpatch.cc mpatch.o fuzzutil.o -o mpatch
+	  -I../../mercurial mpatch.cc mpatch.o -o mpatch
 
 mpatch-oss-fuzz.o: ../../mercurial/mpatch.c
 	$(CC) $(CFLAGS) -c -o mpatch-oss-fuzz.o ../../mercurial/mpatch.c
 
-mpatch_fuzzer: mpatch.cc mpatch-oss-fuzz.o fuzzutil-oss-fuzz.o
+mpatch_fuzzer: mpatch.cc mpatch-oss-fuzz.o 
 	$(CXX) $(CXXFLAGS) -std=c++17 -I../../mercurial mpatch.cc \
-	  mpatch-oss-fuzz.o fuzzutil-oss-fuzz.o -lFuzzingEngine -o \
+	  mpatch-oss-fuzz.o -lFuzzingEngine -o \
 	  $$OUT/mpatch_fuzzer
 
 mpatch_corpus.zip:
@@ -60,19 +51,19 @@ 
 	  $<
 
 xdiff: CXXFLAGS += -std=c++17
-xdiff: xdiff.cc xdiffi.o xprepare.o xutils.o fuzzutil.o
+xdiff: xdiff.cc xdiffi.o xprepare.o xutils.o 
 	$(CXX) $(CXXFLAGS) -DHG_FUZZER_INCLUDE_MAIN=1 -g -O1 -fsanitize=fuzzer-no-link,address \
 	  -I../../mercurial xdiff.cc \
-	  xdiffi.o xprepare.o xutils.o fuzzutil.o -o xdiff
+	  xdiffi.o xprepare.o xutils.o -o xdiff
 
 fuzz-x%.o: ../../mercurial/thirdparty/xdiff/x%.c ../../mercurial/thirdparty/xdiff/*.h
 	$(CC) $(CFLAGS) -c \
 	  -o $@ \
 	  $<
 
-xdiff_fuzzer: xdiff.cc fuzz-xdiffi.o fuzz-xprepare.o fuzz-xutils.o fuzzutil-oss-fuzz.o
+xdiff_fuzzer: xdiff.cc fuzz-xdiffi.o fuzz-xprepare.o fuzz-xutils.o 
 	$(CXX) $(CXXFLAGS) -std=c++17 -I../../mercurial xdiff.cc \
-	  fuzz-xdiffi.o fuzz-xprepare.o fuzz-xutils.o fuzzutil-oss-fuzz.o \
+	  fuzz-xdiffi.o fuzz-xprepare.o fuzz-xutils.o \
 	  -lFuzzingEngine -o $$OUT/xdiff_fuzzer
 
 manifest.o: ../../mercurial/cext/manifest.c