ba2a3bf092
Summary: This PR adds a fuzzer to the project and infrastructure to integrate Rocksdb with OSS-Fuzz. OSS-Fuzz is a service run by Google that performs continuous fuzzing of important open source projects. The LevelDB project is also in being fuzzed by OSS-Fuzz (https://github.com/google/oss-fuzz/tree/master/projects/leveldb). Essentially, OSS-Fuzz will perform the fuzzing for you and email you bug reports, coverage reports etc. All we need is a set of email addresses that will receive this information. For cross-referencing, the PR that adds the OSS-Fuzz logic is here: https://github.com/google/oss-fuzz/pull/4642 The `db_fuzzer` of the PR performs stateful fuzzing of Rocksdb by calling a sequence of Rockdb's APIs with random input in each fuzz iteration. Each fuzz iteration, thus, creates a new instance of Rocksdb and operates on this given instance. The goal is to test diverse states of Rocksdb and ensure no state lead to error conditions, e.g. memory corruption vulnerabilities. The fuzzer is similar (although more complex) to the fuzzer that is currently being used to analyse Leveldb (https://github.com/google/oss-fuzz/blob/master/projects/leveldb/fuzz_db.cc) Pull Request resolved: https://github.com/facebook/rocksdb/pull/7674 Reviewed By: pdillinger Differential Revision: D25238536 Pulled By: cheng-chang fbshipit-source-id: 610331c49a77eb68d3b1d7d5ef1b0ce230ac0630
60 lines
2.4 KiB
Makefile
60 lines
2.4 KiB
Makefile
# Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
# This source code is licensed under both the GPLv2 (found in the
|
|
# COPYING file in the root directory) and Apache 2.0 License
|
|
# (found in the LICENSE.Apache file in the root directory).
|
|
|
|
CWD = $(shell pwd)
|
|
|
|
PROTOBUF_CFLAGS = `pkg-config --cflags protobuf`
|
|
PROTOBUF_LDFLAGS = `pkg-config --libs protobuf`
|
|
|
|
PROTOBUF_MUTATOR_CFLAGS = `pkg-config --cflags libprotobuf-mutator`
|
|
PROTOBUF_MUTATOR_LDFLAGS = `pkg-config --libs libprotobuf-mutator`
|
|
|
|
ROCKSDB_INCLUDE_DIR = $(CWD)/../include
|
|
ROCKSDB_LIB_DIR = $(CWD)/..
|
|
|
|
PROTO_IN = $(CWD)/proto
|
|
PROTO_OUT = $(CWD)/proto/gen
|
|
|
|
ifneq ($(FUZZ_ENV), ossfuzz)
|
|
CC = clang++
|
|
CCFLAGS += -std=c++14 -Wall -fsanitize=address,fuzzer
|
|
CFLAGS += $(PROTOBUF_CFLAGS) $(PROTOBUF_MUTATOR_CFLAGS) -I$(PROTO_OUT) -I$(ROCKSDB_INCLUDE_DIR)
|
|
LDFLAGS += $(PROTOBUF_LDFLAGS) $(PROTOBUF_MUTATOR_LDFLAGS) -L$(ROCKSDB_LIB_DIR) -lrocksdb -lz -lbz2
|
|
else
|
|
# OSS-Fuzz sets various environment flags that are used for compilation.
|
|
# These environment flags depend on which type of sanitizer build is being
|
|
# used, however, an ASan build would set the environment flags as follows:
|
|
# CFLAGS="-O1 -fno-omit-frame-pointer -gline-tables-only \
|
|
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address \
|
|
-fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link"
|
|
# CXXFLAGS="-O1 -fno-omit-frame-pointer -gline-tables-only \
|
|
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address \
|
|
-fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link \
|
|
-stdlib=libc++"
|
|
# LIB_FUZZING_ENGINE="-fsanitize=fuzzer"
|
|
CC = $(CXX)
|
|
CCFLAGS = $(CXXFLAGS)
|
|
CFLAGS += $(PROTOBUF_CFLAGS) $(PROTOBUF_MUTATOR_CFLAGS) -I$(PROTO_OUT) -I$(ROCKSDB_INCLUDE_DIR)
|
|
LDFLAGS += $(LIB_FUZZING_ENGINE) $(PROTOBUF_MUTATOR_LDFLAGS) $(PROTOBUF_LDFLAGS) -L$(ROCKSDB_LIB_DIR) -lrocksdb -lz -lbz2
|
|
endif
|
|
|
|
.PHONY: librocksdb gen_proto
|
|
|
|
librocksdb:
|
|
cd $(CWD)/.. && make static_lib
|
|
|
|
gen_proto:
|
|
mkdir -p $(PROTO_OUT)
|
|
protoc \
|
|
--proto_path=$(PROTO_IN) \
|
|
--cpp_out=$(PROTO_OUT) \
|
|
$(PROTO_IN)/*.proto
|
|
|
|
db_fuzzer: librocksdb db_fuzzer.cc
|
|
$(CC) $(CCFLAGS) -o db_fuzzer db_fuzzer.cc $(CFLAGS) $(LDFLAGS)
|
|
|
|
sst_file_writer_fuzzer: librocksdb gen_proto sst_file_writer_fuzzer.cc proto/gen/db_operation.pb.cc
|
|
$(CC) $(CCFLAGS) -o sst_file_writer_fuzzer sst_file_writer_fuzzer.cc proto/gen/db_operation.pb.cc $(CFLAGS) $(LDFLAGS)
|