Make fuzzers C++ programs, not C

Using https://github.com/google/oss-fuzz on .c files says:

clang-7.0: warning: treating 'c' input as 'c++' when in C++ mode, this
behavior is deprecated [-Wdeprecated]
This commit is contained in:
Nigel Tao committed 2018-02-17 15:41:21 +11:00
1 parent b23c235067
commit b182db372a
3 files changed
+13 -12

No files matched your search

@@ -28,11 +28,7 @@ void intentional_segfault() {
void fuzz(wuffs_base__reader1 src_reader, uint32_t hash);
#ifdef __cplusplus
extern "C"
#endif
int
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Hash input as per https://en.wikipedia.org/wiki/Jenkins_hash_function
size_t i = 0;
uint32_t hash = 0;
@@ -45,8 +41,11 @@ extern "C"
hash ^= hash >> 11;
hash += hash << 15;
wuffs_base__buf1 src = {
.ptr = (uint8_t*)(data), .len = size, .wi = size, .closed = true};
wuffs_base__buf1 src = {.ptr = (uint8_t*)(data),
.len = size,
.wi = size,
.ri = 0,
.closed = true};
fuzz((wuffs_base__reader1){.buf = &src}, hash);
return 0;
}
@@ -85,7 +84,7 @@ int main(int argc, char** argv) {
return 1;
}
int fuzz = LLVMFuzzerTestOneInput(data, n);
int fuzz = LLVMFuzzerTestOneInput((const uint8_t*)(data), n);
if (fuzz) {
return fuzz;
}
+3 -2
View File
@@ -23,7 +23,8 @@ such as https://github.com/google/oss-fuzz calling LLVMFuzzerTestOneInput.
When working on the fuzz implementation, or as a sanity check, defining
WUFFS_CONFIG__FUZZLIB_MAIN will let you manually run fuzz over a set of files:
gcc -DWUFFS_CONFIG__FUZZLIB_MAIN gif.c && ./a.out ../../../test/testdata/*.gif
g++ -DWUFFS_CONFIG__FUZZLIB_MAIN gif.cc
./a.out ../../../test/testdata/*.gif
rm -f ./a.out
It should print "PASS", amongst other information, and exit(0).
@@ -35,7 +36,7 @@ It should print "PASS", amongst other information, and exit(0).
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../gen/c/std/gif.c"
#include "../fuzzlib/fuzzlib.c"
#include "../fuzzlib/fuzzlib.cc"
void fuzz(wuffs_base__reader1 src_reader, uint32_t hash) {
void* pixbuf = NULL;
+3 -2
View File
@@ -23,7 +23,8 @@ such as https://github.com/google/oss-fuzz calling LLVMFuzzerTestOneInput.
When working on the fuzz implementation, or as a sanity check, defining
WUFFS_CONFIG__FUZZLIB_MAIN will let you manually run fuzz over a set of files:
gcc -DWUFFS_CONFIG__FUZZLIB_MAIN zlib.c && ./a.out ../../../test/testdata/*.zlib
g++ -DWUFFS_CONFIG__FUZZLIB_MAIN zlib.cc
./a.out ../../../test/testdata/*.zlib
rm -f ./a.out
It should print "PASS", amongst other information, and exit(0).
@@ -36,7 +37,7 @@ It should print "PASS", amongst other information, and exit(0).
// program to generate a stand-alone C file.
#include "../../../gen/c/std/deflate.c"
#include "../../../gen/c/std/zlib.c"
#include "../fuzzlib/fuzzlib.c"
#include "../fuzzlib/fuzzlib.cc"
void fuzz(wuffs_base__reader1 src_reader, uint32_t hash) {
wuffs_zlib__status s;