target.c 1.1 KB

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