File: fuzz-main.c

package info (click to toggle)
libslirp 4.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,136 kB
  • sloc: ansic: 14,089; sh: 98; python: 34; makefile: 3
file content (36 lines) | stat: -rw-r--r-- 871 bytes parent folder | download
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
#include <glib.h>
#include <stdlib.h>

#define MIN_NUMBER_OF_RUNS 1
#define EXIT_TEST_SKIP 77

extern int LLVMFuzzerTestOneInput(const unsigned char *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) {
                g_free(buf);
                return EXIT_TEST_SKIP;
            }
        }
        g_free(buf);
    }

    return EXIT_SUCCESS;
}