summaryrefslogtreecommitdiff
path: root/fuzz/compose/target.c
blob: a7f15c11502979fcd3456806253252f93b31e0d7 (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
/*
 * A target program for fuzzing the Compose text format.
 *
 * Currently, just parses an input file, and hopefully doesn't crash or hang.
 */
#include "config.h"

#include <assert.h>

#include "xkbcommon/xkbcommon.h"
#include "xkbcommon/xkbcommon-compose.h"

int
main(int argc, char *argv[])
{
    struct xkb_context *ctx;
    FILE *file;
    struct xkb_compose_table *table;

    if (argc != 2) {
        fprintf(stderr, "usage: %s <file>\n", argv[0]);
        return 1;
    }

    ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES | XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
    assert(ctx);

#ifdef __AFL_HAVE_MANUAL_CONTROL
  __AFL_INIT();

    while (__AFL_LOOP(1000))
#endif
    {
        file = fopen(argv[1], "r");
        assert(file);
        table = xkb_compose_table_new_from_file(ctx, file,
                                                "en_US.UTF-8",
                                                XKB_COMPOSE_FORMAT_TEXT_V1,
                                                XKB_COMPOSE_COMPILE_NO_FLAGS);
        xkb_compose_table_unref(table);
        fclose(file);
    }

    puts(table ? "OK" : "FAIL");
    xkb_context_unref(ctx);
}