mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 16:52:18 +01:00
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:
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);
|
void fuzz(wuffs_base__reader1 src_reader, uint32_t hash);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||||
extern "C"
|
|
||||||
#endif
|
|
||||||
int
|
|
||||||
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|
||||||
// Hash input as per https://en.wikipedia.org/wiki/Jenkins_hash_function
|
// Hash input as per https://en.wikipedia.org/wiki/Jenkins_hash_function
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
uint32_t hash = 0;
|
uint32_t hash = 0;
|
||||||
@@ -45,8 +41,11 @@ extern "C"
|
|||||||
hash ^= hash >> 11;
|
hash ^= hash >> 11;
|
||||||
hash += hash << 15;
|
hash += hash << 15;
|
||||||
|
|
||||||
wuffs_base__buf1 src = {
|
wuffs_base__buf1 src = {.ptr = (uint8_t*)(data),
|
||||||
.ptr = (uint8_t*)(data), .len = size, .wi = size, .closed = true};
|
.len = size,
|
||||||
|
.wi = size,
|
||||||
|
.ri = 0,
|
||||||
|
.closed = true};
|
||||||
fuzz((wuffs_base__reader1){.buf = &src}, hash);
|
fuzz((wuffs_base__reader1){.buf = &src}, hash);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -85,7 +84,7 @@ int main(int argc, char** argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fuzz = LLVMFuzzerTestOneInput(data, n);
|
int fuzz = LLVMFuzzerTestOneInput((const uint8_t*)(data), n);
|
||||||
if (fuzz) {
|
if (fuzz) {
|
||||||
return fuzz;
|
return fuzz;
|
||||||
}
|
}
|
||||||
@@ -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
|
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:
|
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
|
rm -f ./a.out
|
||||||
|
|
||||||
It should print "PASS", amongst other information, and exit(0).
|
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
|
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||||
// program to generate a stand-alone C file.
|
// program to generate a stand-alone C file.
|
||||||
#include "../../../gen/c/std/gif.c"
|
#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 fuzz(wuffs_base__reader1 src_reader, uint32_t hash) {
|
||||||
void* pixbuf = NULL;
|
void* pixbuf = NULL;
|
||||||
@@ -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
|
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:
|
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
|
rm -f ./a.out
|
||||||
|
|
||||||
It should print "PASS", amongst other information, and exit(0).
|
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.
|
// program to generate a stand-alone C file.
|
||||||
#include "../../../gen/c/std/deflate.c"
|
#include "../../../gen/c/std/deflate.c"
|
||||||
#include "../../../gen/c/std/zlib.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) {
|
void fuzz(wuffs_base__reader1 src_reader, uint32_t hash) {
|
||||||
wuffs_zlib__status s;
|
wuffs_zlib__status s;
|
||||||
Reference in new issue
Block a user