fuzzing_include_am.py 3.9 KB

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