File: fuzzer.c

package info (click to toggle)
libcacard 1%3A2.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,756 kB
  • sloc: ansic: 9,723; sh: 4,874; makefile: 192
file content (38 lines) | stat: -rw-r--r-- 822 bytes parent folder | download | duplicates (2)
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
/* 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;
    size_t n_read, len;
    unsigned char *buf;

    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);
    assert (n_read == len);
    LLVMFuzzerTestOneInput (buf, len);

    free (buf);
    printf ("Done!\n");
    return 0;
}