Skip to content

Commit

Permalink
oss-fuzz: Add raw fuzzer
Browse files Browse the repository at this point in the history
Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
DavidKorczynski committed Jun 24, 2023
1 parent 6c750d9 commit c411777
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
6 changes: 5 additions & 1 deletion oss-fuzz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
CPPCHECK_DIR=..
INCLUDE_DIR=-I ${CPPCHECK_DIR}/lib -I ${CPPCHECK_DIR}/externals/picojson -I ${CPPCHECK_DIR}/externals/simplecpp -I ${CPPCHECK_DIR}/externals/tinyxml2 -I ${CPPCHECK_DIR}/externals
SRC_FILES=main.cpp type2.cpp ${CPPCHECK_DIR}/externals/simplecpp/simplecpp.cpp ${CPPCHECK_DIR}/externals/tinyxml2/tinyxml2.cpp ${CPPCHECK_DIR}/lib/*.cpp
RAW_FUZZER_SRC_FILES=raw_fuzzer.cpp ${CPPCHECK_DIR}/externals/simplecpp/simplecpp.cpp ${CPPCHECK_DIR}/externals/tinyxml2/tinyxml2.cpp ${CPPCHECK_DIR}/lib/*.cpp

all: oss-fuzz-client translate
all: oss-fuzz-client translate raw_fuzzer

oss-fuzz-client: main.cpp type2.cpp type2.h
${CXX} -std=c++11 -g ${CXXFLAGS} -o oss-fuzz-client ${INCLUDE_DIR} ${SRC_FILES} ${LIB_FUZZING_ENGINE}

raw_fuzzer: raw_fuzzer.cpp
${CXX} -std=c++11 -g ${CXXFLAGS} -o raw_fuzzer ${INCLUDE_DIR} ${RAW_FUZZER_SRC_FILES} ${LIB_FUZZING_ENGINE}

translate: translate.cpp type2.cpp type2.h
${CXX} -std=c++11 -g ${CXXFLAGS} -o translate type2.cpp translate.cpp

Expand Down
49 changes: 49 additions & 0 deletions oss-fuzz/raw_fuzzer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2023 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "cppcheck.h"
//#include "type2.h"

enum class Color;

class DummyErrorLogger : public ErrorLogger {
public:
void reportOut(const std::string& /*outmsg*/, Color /*c*/) override {}
void reportErr(const ErrorMessage& /*msg*/) override {}
void reportProgress(const std::string& /*filename*/,
const char /*stage*/[],
const std::size_t /*value*/) override {} // FN
};

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataSize);

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataSize)
{
if (dataSize < 10000) {
std::string code(reinterpret_cast<const char*>(data), dataSize);

DummyErrorLogger errorLogger;
CppCheck cppcheck(errorLogger, false, nullptr);
cppcheck.settings().addEnabled("all");
cppcheck.settings().certainty.setEnabled(Certainty::inconclusive, true);
cppcheck.check("test.cpp", code);
}
return 0;
}


0 comments on commit c411777

Please sign in to comment.