1 /*
2 * A target program for fuzzing the Compose 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 #include "xkbcommon/xkbcommon-compose.h"
12
13 int
main(int argc,char * argv[])14 main(int argc, char *argv[])
15 {
16 struct xkb_context *ctx;
17 FILE *file;
18 struct xkb_compose_table *table;
19
20 if (argc != 2) {
21 fprintf(stderr, "usage: %s <file>\n", argv[0]);
22 return 1;
23 }
24
25 ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES | XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
26 assert(ctx);
27
28 #ifdef __AFL_HAVE_MANUAL_CONTROL
29 __AFL_INIT();
30
31 while (__AFL_LOOP(1000))
32 #endif
33 {
34 file = fopen(argv[1], "rb");
35 assert(file);
36 table = xkb_compose_table_new_from_file(ctx, file,
37 "en_US.UTF-8",
38 XKB_COMPOSE_FORMAT_TEXT_V1,
39 XKB_COMPOSE_COMPILE_NO_FLAGS);
40 xkb_compose_table_unref(table);
41 fclose(file);
42 }
43
44 puts(table ? "OK" : "FAIL");
45 xkb_context_unref(ctx);
46 }
47