fuzzing_include_am.py 3.9 KB

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