fuzzing_include_am.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. FUZZERS = """
  2. consensus
  3. descriptor
  4. diff
  5. diff-apply
  6. extrainfo
  7. hsdescv2
  8. http
  9. iptsv2
  10. microdesc
  11. vrs
  12. """
  13. PREAMBLE = r"""
  14. FUZZING_CPPFLAGS = \
  15. $(src_test_AM_CPPFLAGS) $(TEST_CPPFLAGS)
  16. FUZZING_CFLAGS = \
  17. $(AM_CFLAGS) $(TEST_CFLAGS)
  18. FUZZING_LDFLAG = \
  19. @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ @TOR_LDFLAGS_libevent@
  20. FUZZING_LIBS = \
  21. src/or/libtor-testing.a \
  22. src/common/libor-crypto-testing.a \
  23. $(LIBKECCAK_TINY) \
  24. $(LIBDONNA) \
  25. src/common/libor-testing.a \
  26. src/common/libor-ctime-testing.a \
  27. src/common/libor-event-testing.a \
  28. src/trunnel/libor-trunnel-testing.a \
  29. @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \
  30. @TOR_LIBEVENT_LIBS@ \
  31. @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@ \
  32. @TOR_SYSTEMD_LIBS@
  33. oss-fuzz-prereqs: \
  34. src/or/libtor-testing.a \
  35. src/common/libor-crypto-testing.a \
  36. $(LIBKECCAK_TINY) \
  37. $(LIBDONNA) \
  38. src/common/libor-testing.a \
  39. src/common/libor-ctime-testing.a \
  40. src/common/libor-event-testing.a \
  41. src/trunnel/libor-trunnel-testing.a
  42. noinst_HEADERS += \
  43. src/test/fuzz/fuzzing.h
  44. LIBFUZZER = /home/nickm/build/libfuzz/libFuzzer.a
  45. LIBFUZZER_CPPFLAGS = $(FUZZING_CPPFLAGS) -DLLVM_FUZZ
  46. LIBFUZZER_CFLAGS = $(FUZZING_CFLAGS)
  47. LIBFUZZER_LDFLAG = $(FUZZING_LDFLAG)
  48. LIBFUZZER_LIBS = $(FUZZING_LIBS) $(LIBFUZZER) -lstdc++
  49. LIBOSS_FUZZ_CPPFLAGS = $(FUZZING_CPPFLAGS) -DLLVM_FUZZ
  50. LIBOSS_FUZZ_CFLAGS = $(FUZZING_CFLAGS)
  51. """
  52. POSTAMBLE = r"""
  53. noinst_PROGRAMS += $(FUZZERS) $(LIBFUZZER_FUZZERS)
  54. noinst_LIBRARIES += $(OSS_FUZZ_FUZZERS)
  55. oss-fuzz-fuzzers: oss-fuzz-prereqs $(OSS_FUZZ_FUZZERS)
  56. fuzzers: $(FUZZERS) $(LIBFUZZER_FUZZERS)
  57. test-fuzz-corpora: $(FUZZERS)
  58. $(top_srcdir)/src/test/fuzz_static_testcases.sh
  59. """
  60. ########### No user serviceable parts will follow.
  61. PREAMBLE = PREAMBLE.strip()
  62. POSTAMBLE = POSTAMBLE.strip() # If I use it, it's a word!
  63. FUZZERS = FUZZERS.split()
  64. FUZZERS.sort()
  65. WARNING = """
  66. # This file was generated by fuzzing_include_am.py; do not hand-edit unless
  67. # you enjoy having your changes erased.
  68. """.strip()
  69. print(WARNING)
  70. print(PREAMBLE)
  71. print("\n# ===== AFL fuzzers")
  72. def get_id_name(s):
  73. return s.replace("-", "_")
  74. for fuzzer in FUZZERS:
  75. idname = get_id_name(fuzzer)
  76. print("""\
  77. src_test_fuzz_fuzz_{name}_SOURCES = \\
  78. src/test/fuzz/fuzzing_common.c \\
  79. src/test/fuzz/fuzz_{name}.c
  80. src_test_fuzz_fuzz_{name}_CPPFLAGS = $(FUZZING_CPPFLAGS)
  81. src_test_fuzz_fuzz_{name}_CFLAGS = $(FUZZING_CFLAGS)
  82. src_test_fuzz_fuzz_{name}_LDFLAGS = $(FUZZING_LDFLAG)
  83. src_test_fuzz_fuzz_{name}_LDADD = $(FUZZING_LIBS)
  84. """.format(name=idname))
  85. print("FUZZERS = \\")
  86. print(" \\\n".join("\tsrc/test/fuzz/fuzz-{name}".format(name=fuzzer)
  87. for fuzzer in FUZZERS))
  88. print("\n# ===== libfuzzer")
  89. print("\nif LIBFUZZER_ENABLED")
  90. for fuzzer in FUZZERS:
  91. idname = get_id_name(fuzzer)
  92. print("""\
  93. src_test_fuzz_lf_fuzz_{name}_SOURCES = \\
  94. $(src_test_fuzz_fuzz_{name}_SOURCES)
  95. src_test_fuzz_lf_fuzz_{name}_CPPFLAGS = $(LIBFUZZER_CPPFLAGS)
  96. src_test_fuzz_lf_fuzz_{name}_CFLAGS = $(LIBFUZZER_CFLAGS)
  97. src_test_fuzz_lf_fuzz_{name}_LDFLAGS = $(LIBFUZZER_LDFLAG)
  98. src_test_fuzz_lf_fuzz_{name}_LDADD = $(LIBFUZZER_LIBS)
  99. """.format(name=idname))
  100. print("LIBFUZZER_FUZZERS = \\")
  101. print(" \\\n".join("\tsrc/test/fuzz/lf-fuzz-{name}".format(name=fuzzer)
  102. for fuzzer in FUZZERS))
  103. print("""
  104. else
  105. LIBFUZZER_FUZZERS =
  106. endif""")
  107. print("\n# ===== oss-fuzz\n")
  108. print("if OSS_FUZZ_ENABLED")
  109. for fuzzer in FUZZERS:
  110. idname = get_id_name(fuzzer)
  111. print("""\
  112. src_test_fuzz_liboss_fuzz_{name}_a_SOURCES = \\
  113. $(src_test_fuzz_fuzz_{name}_SOURCES)
  114. src_test_fuzz_liboss_fuzz_{name}_a_CPPFLAGS = $(LIBOSS_FUZZ_CPPFLAGS)
  115. src_test_fuzz_liboss_fuzz_{name}_a_CFLAGS = $(LIBOSS_FUZZ_CFLAGS)
  116. """.format(name=idname))
  117. print("OSS_FUZZ_FUZZERS = \\")
  118. print(" \\\n".join("\tsrc/test/fuzz/liboss-fuzz-{name}.a".format(name=fuzzer)
  119. for fuzzer in FUZZERS))
  120. print("""
  121. else
  122. OSS_FUZZ_FUZZERS =
  123. endif""")
  124. print("")
  125. print(POSTAMBLE)