fuzzing_include_am.py 3.9 KB

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