summaryrefslogtreecommitdiff
path: root/tools/fuzz/libelf/afl-libelf-fuzzer.c
blob: 115c98e22e0bdd7830529225850ed693dbde43fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

extern int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size);

#define INPUT_SIZE  4096
static uint8_t input[INPUT_SIZE];

int main(int argc, char **argv)
{
    size_t size;
    FILE *fp;

    setbuf(stdout, NULL);

    if ( argc != 2 )
    {
        printf("Expecting only one argument\n");
        exit(-1);
    }

    fp = fopen(argv[1], "rb");
    if ( fp == NULL )
    {
        perror("fopen");
        exit(-1);
    }

    size = fread(input, 1, INPUT_SIZE, fp);

    if ( ferror(fp) )
    {
        perror("fread");
        exit(-1);
    }

    if ( !feof(fp) )
    {
        printf("Input too large\n");
        exit(-1);
    }

    fclose(fp);

    return LLVMFuzzerTestOneInput(input, size);
}

/*
 * Local variables:
 * mode: C
 * c-file-style: "BSD"
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 */