fuzzing_include_am.py 3.5 KB

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