fuzzing_include_am.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. if UNITTESTS_ENABLED
  85. src_test_fuzz_fuzz_{name}_SOURCES = \\
  86. src/test/fuzz/fuzzing_common.c \\
  87. src/test/fuzz/fuzz_{name}.c
  88. src_test_fuzz_fuzz_{name}_CPPFLAGS = $(FUZZING_CPPFLAGS)
  89. src_test_fuzz_fuzz_{name}_CFLAGS = $(FUZZING_CFLAGS)
  90. src_test_fuzz_fuzz_{name}_LDFLAGS = $(FUZZING_LDFLAG)
  91. src_test_fuzz_fuzz_{name}_LDADD = $(FUZZING_LIBS)
  92. endif
  93. """.format(name=idname))
  94. print("if UNITTESTS_ENABLED")
  95. print("FUZZERS = \\")
  96. print(" \\\n".join("\tsrc/test/fuzz/fuzz-{name}".format(name=fuzzer)
  97. for fuzzer in FUZZERS))
  98. print("endif")
  99. print("\n# ===== libfuzzer")
  100. print("\nif LIBFUZZER_ENABLED")
  101. for fuzzer in FUZZERS:
  102. idname = get_id_name(fuzzer)
  103. print("""\
  104. if UNITTESTS_ENABLED
  105. src_test_fuzz_lf_fuzz_{name}_SOURCES = \\
  106. $(src_test_fuzz_fuzz_{name}_SOURCES)
  107. src_test_fuzz_lf_fuzz_{name}_CPPFLAGS = $(LIBFUZZER_CPPFLAGS)
  108. src_test_fuzz_lf_fuzz_{name}_CFLAGS = $(LIBFUZZER_CFLAGS)
  109. src_test_fuzz_lf_fuzz_{name}_LDFLAGS = $(LIBFUZZER_LDFLAG)
  110. src_test_fuzz_lf_fuzz_{name}_LDADD = $(LIBFUZZER_LIBS)
  111. endif
  112. """.format(name=idname))
  113. print("LIBFUZZER_FUZZERS = \\")
  114. print(" \\\n".join("\tsrc/test/fuzz/lf-fuzz-{name}".format(name=fuzzer)
  115. for fuzzer in FUZZERS))
  116. print("""
  117. else
  118. LIBFUZZER_FUZZERS =
  119. endif""")
  120. print("\n# ===== oss-fuzz\n")
  121. print("if OSS_FUZZ_ENABLED")
  122. for fuzzer in FUZZERS:
  123. idname = get_id_name(fuzzer)
  124. print("""\
  125. if UNITTESTS_ENABLED
  126. src_test_fuzz_liboss_fuzz_{name}_a_SOURCES = \\
  127. $(src_test_fuzz_fuzz_{name}_SOURCES)
  128. src_test_fuzz_liboss_fuzz_{name}_a_CPPFLAGS = $(LIBOSS_FUZZ_CPPFLAGS)
  129. src_test_fuzz_liboss_fuzz_{name}_a_CFLAGS = $(LIBOSS_FUZZ_CFLAGS)
  130. endif
  131. """.format(name=idname))
  132. print("OSS_FUZZ_FUZZERS = \\")
  133. print(" \\\n".join("\tsrc/test/fuzz/liboss-fuzz-{name}.a".format(name=fuzzer)
  134. for fuzzer in FUZZERS))
  135. print("""
  136. else
  137. OSS_FUZZ_FUZZERS =
  138. endif""")
  139. print("")
  140. print(POSTAMBLE)