aboutsummaryrefslogtreecommitdiff
path: root/fuzzing/reproducer.c
blob: 49704af7a532db040e82b92a93aed66b0b34f91b (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
#ifdef _WIN32
/* as defined in sdkddkver.h */
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600 /* Vista */
#endif
#include <ws2tcpip.h>
#endif

#include <glib.h>
#include <stdlib.h>
#include "../src/libslirp.h"
#include "helper.h"

#define MIN_NUMBER_OF_RUNS 1
#define EXIT_TEST_SKIP 77

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

int main(int argc, char **argv)
{
    int i, j;

    for (i = 1; i < argc; i++) {
        GError *err = NULL;
        char *name = argv[i];
        char *buf;
        size_t size;

        if (!g_file_get_contents(name, &buf, &size, &err)) {
            g_warning("Failed to read '%s': %s", name, err->message);
            g_clear_error(&err);
            return EXIT_FAILURE;
        }

        g_print("%s...\n", name);
        for (j = 0; j < MIN_NUMBER_OF_RUNS; j++) {
            if (LLVMFuzzerTestOneInput((void *)buf, size) == EXIT_TEST_SKIP) {
                return EXIT_TEST_SKIP;
            }
        }
        g_free(buf);
    }

    return EXIT_SUCCESS;
}