mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-31 00:03:07 +03:00
fuzz: Simplify definition of fuzzing targets and build them also with gcc
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
5411e0821f
commit
62a0229f16
39
tests/fuzz/fuzzer.c
Normal file
39
tests/fuzz/fuzzer.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* Simpler gnu89 version of StandaloneFuzzTargetMain.c from LLVM */
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int LLVMFuzzerTestOneInput (const unsigned char *data, size_t size);
|
||||
__attribute__((weak)) int LLVMFuzzerInitialize(int *argc, char ***argv);
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
size_t n_read, len;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
if (argc < 2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (LLVMFuzzerInitialize) {
|
||||
LLVMFuzzerInitialize(&argc, &argv);
|
||||
}
|
||||
|
||||
f = fopen (argv[1], "r");
|
||||
assert (f);
|
||||
fseek (f, 0, SEEK_END);
|
||||
len = ftell (f);
|
||||
fseek (f, 0, SEEK_SET);
|
||||
buf = (unsigned char*) malloc (len);
|
||||
n_read = fread (buf, 1, len, f);
|
||||
fclose (f);
|
||||
assert (n_read == len);
|
||||
LLVMFuzzerTestOneInput (buf, len);
|
||||
|
||||
free (buf);
|
||||
printf ("Done!\n");
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user