summaryrefslogtreecommitdiffstats
path: root/libmount/src/fuzz.c
blob: 2c847144302eb43c65748473fbcefb835bcbbd26 (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
#include "fuzz.h"
#include "xalloc.h"
#include "mountP.h"

#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
        struct libmnt_table *tb = NULL;
        FILE *f = NULL;

        if (size == 0)
                return 0;

        // 128Kb should be enough to trigger all the issues we're interested in
        if (size > 131072)
                return 0;

        tb = mnt_new_table();
        if (!tb)
		err_oom();

        f = fmemopen((char*) data, size, "re");
        if (!f)
		err(EXIT_FAILURE, "fmemopen() failed");

        mnt_table_enable_comments(tb, TRUE);
        (void) mnt_table_parse_stream(tb, f, "mountinfo");

        mnt_unref_table(tb);
        fclose(f);

        return 0;
}