Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oss-fuzz: Add raw fuzzer #5185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 48 additions & 0 deletions oss-fuzz/raw_fuzzer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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"

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;
}