fuzzing_include_am.py 3.9 KB

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