Update to 0.3.0
[platform/upstream/libxkbcommon.git] / fuzz / keymap / target.c
1 /*
2  * A target program for fuzzing the XKB keymap text format.
3  *
4  * Currently, just parses an input file, and hopefully doesn't crash or hang.
5  */
6 #include "config.h"
7
8 #include <assert.h>
9
10 #include "xkbcommon/xkbcommon.h"
11
12 int
13 main(int argc, char *argv[])
14 {
15     struct xkb_context *ctx;
16     FILE *file;
17     struct xkb_keymap *keymap;
18
19     if (argc != 2) {
20         fprintf(stderr, "usage: %s <file>\n", argv[0]);
21         return 1;
22     }
23
24     ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES | XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
25     assert(ctx);
26
27 #ifdef __AFL_HAVE_MANUAL_CONTROL
28   __AFL_INIT();
29
30     while (__AFL_LOOP(1000))
31 #endif
32     {
33         file = fopen(argv[1], "rb");
34         assert(file);
35         keymap = xkb_keymap_new_from_file(ctx, file,
36                                           XKB_KEYMAP_FORMAT_TEXT_V1,
37                                           XKB_KEYMAP_COMPILE_NO_FLAGS);
38         xkb_keymap_unref(keymap);
39         fclose(file);
40     }
41
42     puts(keymap ? "OK" : "FAIL");
43     xkb_context_unref(ctx);
44 }