7e88bb5e53
The current fuzzshark target built by CMake is not usable for fuzzing. Address this by adding a new ENABLE_FUZZER option that enables mandatory instrumentation and libFuzzer linking options for the fuzzshark binary. Create more CMake targets for specific fuzzing targets such as fuzzshark_ip and fuzzshark_ip_proto-udp. These targets are not built by default, either build individual targets or use the all-fuzzers target. Now these binaries are not specific to oss-fuzz, so move them to a new directory (perhaps the corpora can be added here in the future). oss-fuzz build.sh is simplified and reuses the CMake targets. When OSS_FUZZ is set, it will force static linking with external libraries and limit parallel linker jobs (maybe not necessary for Google's oss-fuzz builders, but my 8G/6c VM ran out of memory). Change-Id: If3ba8f60ea1f5c3bd2131223050a81f9acbce05d Reviewed-on: https://code.wireshark.org/review/30228 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
148 lines
6 KiB
C
148 lines
6 KiB
C
/* based on http://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerInterface.h r321218 (20 Dec 2017) */
|
|
|
|
/* http://llvm.org/svn/llvm-project/compiler-rt/trunk/LICENSE.TXT follows */
|
|
|
|
/*
|
|
==============================================================================
|
|
compiler_rt License
|
|
==============================================================================
|
|
|
|
The compiler_rt library is dual licensed under both the University of Illinois
|
|
"BSD-Like" license and the MIT license. As a user of this code you may choose
|
|
to use it under either license. As a contributor, you agree to allow your code
|
|
to be used under both.
|
|
|
|
Full text of the relevant licenses is included below.
|
|
|
|
==============================================================================
|
|
|
|
University of Illinois/NCSA
|
|
Open Source License
|
|
|
|
Copyright (c) 2009-2016 by the contributors listed in CREDITS.TXT
|
|
|
|
All rights reserved.
|
|
|
|
Developed by:
|
|
|
|
LLVM Team
|
|
|
|
University of Illinois at Urbana-Champaign
|
|
|
|
http://llvm.org
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
this software and associated documentation files (the "Software"), to deal with
|
|
the Software without restriction, including without limitation the rights to
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
of the Software, and to permit persons to whom the Software is furnished to do
|
|
so, subject to the following conditions:
|
|
|
|
* Redistributions of source code must retain the above copyright notice,
|
|
this list of conditions and the following disclaimers.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
this list of conditions and the following disclaimers in the
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the names of the LLVM Team, University of Illinois at
|
|
Urbana-Champaign, nor the names of its contributors may be used to
|
|
endorse or promote products derived from this Software without specific
|
|
prior written permission.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
|
|
SOFTWARE.
|
|
|
|
==============================================================================
|
|
|
|
Copyright (c) 2009-2015 by the contributors listed in CREDITS.TXT
|
|
|
|
SPDX-License-Identifier: MIT
|
|
|
|
==============================================================================
|
|
Copyrights and Licenses for Third Party Software Distributed with LLVM:
|
|
==============================================================================
|
|
The LLVM software contains code written by third parties. Such software will
|
|
have its own individual LICENSE.TXT file in the directory in which it appears.
|
|
This file will describe the copyrights, license, and restrictions which apply
|
|
to that code.
|
|
|
|
The disclaimer of warranty in the University of Illinois Open Source License
|
|
applies to all code in the LLVM Distribution, and nothing in any of the
|
|
other licenses gives permission to use the names of the LLVM Team or the
|
|
University of Illinois to endorse or promote products derived from this
|
|
Software.
|
|
*/
|
|
//===- FuzzerInterface.h - Interface header for the Fuzzer ------*- C++ -* ===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
// Define the interface between libFuzzer and the library being tested.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// NOTE: the libFuzzer interface is thin and in the majority of cases
|
|
// you should not include this file into your target. In 95% of cases
|
|
// all you need is to define the following function in your file:
|
|
// extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
|
|
|
|
// WARNING: keep the interface in C.
|
|
|
|
#ifndef LLVM_FUZZER_INTERFACE_H
|
|
#define LLVM_FUZZER_INTERFACE_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif // __cplusplus
|
|
|
|
// Mandatory user-provided target function.
|
|
// Executes the code under test with [Data, Data+Size) as the input.
|
|
// libFuzzer will invoke this function *many* times with different inputs.
|
|
// Must return 0.
|
|
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
|
|
|
|
// Optional user-provided initialization function.
|
|
// If provided, this function will be called by libFuzzer once at startup.
|
|
// It may read and modify argc/argv.
|
|
// Must return 0.
|
|
int LLVMFuzzerInitialize(int *argc, char ***argv);
|
|
|
|
// Optional user-provided custom mutator.
|
|
// Mutates raw data in [Data, Data+Size) inplace.
|
|
// Returns the new size, which is not greater than MaxSize.
|
|
// Given the same Seed produces the same mutation.
|
|
size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size, size_t MaxSize,
|
|
unsigned int Seed);
|
|
|
|
// Optional user-provided custom cross-over function.
|
|
// Combines pieces of Data1 & Data2 together into Out.
|
|
// Returns the new size, which is not greater than MaxOutSize.
|
|
// Should produce the same mutation given the same Seed.
|
|
size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1,
|
|
const uint8_t *Data2, size_t Size2,
|
|
uint8_t *Out, size_t MaxOutSize,
|
|
unsigned int Seed);
|
|
|
|
// Experimental, may go away in future.
|
|
// libFuzzer-provided function to be used inside LLVMFuzzerCustomMutator.
|
|
// Mutates raw data in [Data, Data+Size) inplace.
|
|
// Returns the new size, which is not greater than MaxSize.
|
|
size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize);
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
#endif // __cplusplus
|
|
|
|
#endif // LLVM_FUZZER_INTERFACE_H
|