We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Dockerfile error in ffmpeg_ffmpeg_demuxer_fuzzer
There is an issue in the Dockerfile to build ffmpeg_ffmpeg_demuxer_fuzzer at this line:

https://github.com/google/fuzzbench/blob/master/benchmarks/ffmpeg_ffmpeg_demuxer_fuzzer/Dockerfile#L17

Consequently you cannot build this benchmark. I tried to fix it by using one of the two hashes, but the compilation does not work in any case (even if with two different errors).

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `fuzzers/aflplusplus/fuzzer.py`
Content:
```
1 # Copyright 2020 Google LLC
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 """Integration code for AFLplusplus fuzzer."""
16 
17 import os
18 import shutil
19 
20 from fuzzers.afl import fuzzer as afl_fuzzer
21 from fuzzers import utils
22 
23 
24 def get_cmplog_build_directory(target_directory):
25     """Return path to CmpLog target directory."""
26     return os.path.join(target_directory, 'cmplog')
27 
28 
29 def get_uninstrumented_build_directory(target_directory):
30     """Return path to CmpLog target directory."""
31     return os.path.join(target_directory, 'uninstrumented')
32 
33 
34 def build(*args):  # pylint: disable=too-many-branches,too-many-statements
35     """Build benchmark."""
36     # BUILD_MODES is not already supported by fuzzbench, meanwhile we provide
37     # a default configuration.
38 
39     build_modes = list(args)
40     if 'BUILD_MODES' in os.environ:
41         build_modes = os.environ['BUILD_MODES'].split(',')
42 
43     # Placeholder comment.
44     build_directory = os.environ['OUT']
45 
46     # If nothing was set this is the default:
47     if not build_modes:
48         build_modes = ['tracepc', 'cmplog', 'dict2file']
49 
50     # For bug type benchmarks we have to instrument via native clang pcguard :(
51     build_flags = os.environ['CFLAGS']
52     if build_flags.find(
53             'array-bounds'
54     ) != -1 and 'qemu' not in build_modes and 'classic' not in build_modes:
55         build_modes[0] = 'native'
56 
57     # Instrumentation coverage modes:
58     if 'lto' in build_modes:
59         os.environ['CC'] = '/afl/afl-clang-lto'
60         os.environ['CXX'] = '/afl/afl-clang-lto++'
61         edge_file = build_directory + '/aflpp_edges.txt'
62         os.environ['AFL_LLVM_DOCUMENT_IDS'] = edge_file
63         if os.path.isfile('/usr/local/bin/llvm-ranlib-13'):
64             os.environ['RANLIB'] = 'llvm-ranlib-13'
65             os.environ['AR'] = 'llvm-ar-13'
66             os.environ['AS'] = 'llvm-as-13'
67         elif os.path.isfile('/usr/local/bin/llvm-ranlib-12'):
68             os.environ['RANLIB'] = 'llvm-ranlib-12'
69             os.environ['AR'] = 'llvm-ar-12'
70             os.environ['AS'] = 'llvm-as-12'
71         else:
72             os.environ['RANLIB'] = 'llvm-ranlib'
73             os.environ['AR'] = 'llvm-ar'
74             os.environ['AS'] = 'llvm-as'
75     elif 'qemu' in build_modes:
76         os.environ['CC'] = 'clang'
77         os.environ['CXX'] = 'clang++'
78     elif 'gcc' in build_modes:
79         os.environ['CC'] = 'afl-gcc-fast'
80         os.environ['CXX'] = 'afl-g++-fast'
81     else:
82         os.environ['CC'] = '/afl/afl-clang-fast'
83         os.environ['CXX'] = '/afl/afl-clang-fast++'
84 
85     print('AFL++ build: ')
86     print(build_modes)
87 
88     if 'qemu' in build_modes or 'symcc' in build_modes:
89         os.environ['CFLAGS'] = ' '.join(utils.NO_SANITIZER_COMPAT_CFLAGS)
90         cxxflags = [utils.LIBCPLUSPLUS_FLAG] + utils.NO_SANITIZER_COMPAT_CFLAGS
91         os.environ['CXXFLAGS'] = ' '.join(cxxflags)
92 
93     if 'tracepc' in build_modes or 'pcguard' in build_modes:
94         os.environ['AFL_LLVM_USE_TRACE_PC'] = '1'
95     elif 'classic' in build_modes:
96         os.environ['AFL_LLVM_INSTRUMENT'] = 'CLASSIC'
97     elif 'native' in build_modes:
98         os.environ['AFL_LLVM_INSTRUMENT'] = 'LLVMNATIVE'
99 
100     # Instrumentation coverage options:
101     # Do not use a fixed map location (LTO only)
102     if 'dynamic' in build_modes:
103         os.environ['AFL_LLVM_MAP_DYNAMIC'] = '1'
104     # Use a fixed map location (LTO only)
105     if 'fixed' in build_modes:
106         os.environ['AFL_LLVM_MAP_ADDR'] = '0x10000'
107     # Generate an extra dictionary.
108     if 'dict2file' in build_modes or 'native' in build_modes:
109         os.environ['AFL_LLVM_DICT2FILE'] = build_directory + '/afl++.dict'
110     # Enable context sentitivity for LLVM mode (non LTO only)
111     if 'ctx' in build_modes:
112         os.environ['AFL_LLVM_CTX'] = '1'
113     # Enable N-gram coverage for LLVM mode (non LTO only)
114     if 'ngram2' in build_modes:
115         os.environ['AFL_LLVM_NGRAM_SIZE'] = '2'
116     elif 'ngram3' in build_modes:
117         os.environ['AFL_LLVM_NGRAM_SIZE'] = '3'
118     elif 'ngram4' in build_modes:
119         os.environ['AFL_LLVM_NGRAM_SIZE'] = '4'
120     elif 'ngram5' in build_modes:
121         os.environ['AFL_LLVM_NGRAM_SIZE'] = '5'
122     elif 'ngram6' in build_modes:
123         os.environ['AFL_LLVM_NGRAM_SIZE'] = '6'
124     elif 'ngram7' in build_modes:
125         os.environ['AFL_LLVM_NGRAM_SIZE'] = '7'
126     elif 'ngram8' in build_modes:
127         os.environ['AFL_LLVM_NGRAM_SIZE'] = '8'
128     elif 'ngram16' in build_modes:
129         os.environ['AFL_LLVM_NGRAM_SIZE'] = '16'
130     if 'ctx1' in build_modes:
131         os.environ['AFL_LLVM_CTX_K'] = '1'
132     elif 'ctx2' in build_modes:
133         os.environ['AFL_LLVM_CTX_K'] = '2'
134     elif 'ctx3' in build_modes:
135         os.environ['AFL_LLVM_CTX_K'] = '3'
136     elif 'ctx4' in build_modes:
137         os.environ['AFL_LLVM_CTX_K'] = '4'
138 
139     # Only one of the following OR cmplog
140     # enable laf-intel compare splitting
141     if 'laf' in build_modes:
142         os.environ['AFL_LLVM_LAF_SPLIT_SWITCHES'] = '1'
143         os.environ['AFL_LLVM_LAF_SPLIT_COMPARES'] = '1'
144         os.environ['AFL_LLVM_LAF_SPLIT_FLOATS'] = '1'
145         if 'autodict' not in build_modes:
146             os.environ['AFL_LLVM_LAF_TRANSFORM_COMPARES'] = '1'
147 
148     if 'eclipser' in build_modes:
149         os.environ['FUZZER_LIB'] = '/libStandaloneFuzzTarget.a'
150     else:
151         os.environ['FUZZER_LIB'] = '/libAFLDriver.a'
152 
153     # Some benchmarks like lcms
154     # (see: https://github.com/mm2/Little-CMS/commit/ab1093539b4287c233aca6a3cf53b234faceb792#diff-f0e6d05e72548974e852e8e55dffc4ccR212)
155     # fail to compile if the compiler outputs things to stderr in unexpected
156     # cases. Prevent these failures by using AFL_QUIET to stop afl-clang-fast
157     # from writing AFL specific messages to stderr.
158     os.environ['AFL_QUIET'] = '1'
159     os.environ['AFL_MAP_SIZE'] = '2621440'
160 
161     src = os.getenv('SRC')
162     work = os.getenv('WORK')
163 
164     with utils.restore_directory(src), utils.restore_directory(work):
165         # Restore SRC to its initial state so we can build again without any
166         # trouble. For some OSS-Fuzz projects, build_benchmark cannot be run
167         # twice in the same directory without this.
168         utils.build_benchmark()
169 
170     if 'cmplog' in build_modes and 'qemu' not in build_modes:
171 
172         # CmpLog requires an build with different instrumentation.
173         new_env = os.environ.copy()
174         new_env['AFL_LLVM_CMPLOG'] = '1'
175 
176         # For CmpLog build, set the OUT and FUZZ_TARGET environment
177         # variable to point to the new CmpLog build directory.
178         cmplog_build_directory = get_cmplog_build_directory(build_directory)
179         os.mkdir(cmplog_build_directory)
180         new_env['OUT'] = cmplog_build_directory
181         fuzz_target = os.getenv('FUZZ_TARGET')
182         if fuzz_target:
183             new_env['FUZZ_TARGET'] = os.path.join(cmplog_build_directory,
184                                                   os.path.basename(fuzz_target))
185 
186         print('Re-building benchmark for CmpLog fuzzing target')
187         utils.build_benchmark(env=new_env)
188 
189     if 'symcc' in build_modes:
190 
191         symcc_build_directory = get_uninstrumented_build_directory(
192             build_directory)
193         os.mkdir(symcc_build_directory)
194 
195         # symcc requires an build with different instrumentation.
196         new_env = os.environ.copy()
197         new_env['CC'] = '/symcc/build/symcc'
198         new_env['CXX'] = '/symcc/build/sym++'
199         new_env['SYMCC_OUTPUT_DIR'] = '/tmp'
200         new_env['CXXFLAGS'] = new_env['CXXFLAGS'].replace("-stlib=libc++", "")
201         new_env['FUZZER_LIB'] = '/libfuzzer-harness.o'
202         new_env['OUT'] = symcc_build_directory
203         new_env['SYMCC_LIBCXX_PATH'] = "/libcxx_native_build"
204         new_env['SYMCC_NO_SYMBOLIC_INPUT'] = "1"
205         new_env['SYMCC_SILENT'] = "1"
206 
207         # For CmpLog build, set the OUT and FUZZ_TARGET environment
208         # variable to point to the new CmpLog build directory.
209         new_env['OUT'] = symcc_build_directory
210         fuzz_target = os.getenv('FUZZ_TARGET')
211         if fuzz_target:
212             new_env['FUZZ_TARGET'] = os.path.join(symcc_build_directory,
213                                                   os.path.basename(fuzz_target))
214 
215         print('Re-building benchmark for CmpLog fuzzing target')
216         utils.build_benchmark(env=new_env)
217 
218     shutil.copy('/afl/afl-fuzz', build_directory)
219     if os.path.exists('/afl/afl-qemu-trace'):
220         shutil.copy('/afl/afl-qemu-trace', build_directory)
221     if os.path.exists('/aflpp_qemu_driver_hook.so'):
222         shutil.copy('/aflpp_qemu_driver_hook.so', build_directory)
223     if os.path.exists('/get_frida_entry.sh'):
224         shutil.copy('/afl/afl-frida-trace.so', build_directory)
225         shutil.copy('/get_frida_entry.sh', build_directory)
226 
227 
228 # pylint: disable=too-many-arguments
229 def fuzz(input_corpus,
230          output_corpus,
231          target_binary,
232          flags=tuple(),
233          skip=False,
234          no_cmplog=False):  # pylint: disable=too-many-arguments
235     """Run fuzzer."""
236     # Calculate CmpLog binary path from the instrumented target binary.
237     target_binary_directory = os.path.dirname(target_binary)
238     cmplog_target_binary_directory = (
239         get_cmplog_build_directory(target_binary_directory))
240     target_binary_name = os.path.basename(target_binary)
241     cmplog_target_binary = os.path.join(cmplog_target_binary_directory,
242                                         target_binary_name)
243 
244     afl_fuzzer.prepare_fuzz_environment(input_corpus)
245     # decomment this to enable libdislocator.
246     # os.environ['AFL_ALIGNED_ALLOC'] = '1' # align malloc to max_align_t
247     # os.environ['AFL_PRELOAD'] = '/afl/libdislocator.so'
248 
249     flags = list(flags)
250 
251     if os.path.exists('./afl++.dict'):
252         flags += ['-x', './afl++.dict']
253 
254     # Move the following to skip for upcoming _double tests:
255     if os.path.exists(cmplog_target_binary) and no_cmplog is not False:
256         flags += ['-c', cmplog_target_binary]
257 
258     if not skip:
259         os.environ['AFL_DISABLE_TRIM'] = "1"
260         # os.environ['AFL_FAST_CAL'] = '1'
261         os.environ['AFL_CMPLOG_ONLY_NEW'] = '1'
262         if 'ADDITIONAL_ARGS' in os.environ:
263             flags += os.environ['ADDITIONAL_ARGS'].split(' ')
264 
265     afl_fuzzer.run_afl_fuzz(input_corpus,
266                             output_corpus,
267                             target_binary,
268                             additional_flags=flags)
269
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/fuzzers/aflplusplus/fuzzer.py b/fuzzers/aflplusplus/fuzzer.py
--- a/fuzzers/aflplusplus/fuzzer.py
+++ b/fuzzers/aflplusplus/fuzzer.py
@@ -252,7 +252,7 @@
         flags += ['-x', './afl++.dict']
 
     # Move the following to skip for upcoming _double tests:
-    if os.path.exists(cmplog_target_binary) and no_cmplog is not False:
+    if os.path.exists(cmplog_target_binary) and no_cmplog is False:
         flags += ['-c', cmplog_target_binary]
 
     if not skip:

{"golden_diff": "diff --git a/fuzzers/aflplusplus/fuzzer.py b/fuzzers/aflplusplus/fuzzer.py\n--- a/fuzzers/aflplusplus/fuzzer.py\n+++ b/fuzzers/aflplusplus/fuzzer.py\n@@ -252,7 +252,7 @@\n         flags += ['-x', './afl++.dict']\n \n     # Move the following to skip for upcoming _double tests:\n-    if os.path.exists(cmplog_target_binary) and no_cmplog is not False:\n+    if os.path.exists(cmplog_target_binary) and no_cmplog is False:\n         flags += ['-c', cmplog_target_binary]\n \n     if not skip:\n", "issue": "Dockerfile error in ffmpeg_ffmpeg_demuxer_fuzzer\nThere is an issue in the Dockerfile to build ffmpeg_ffmpeg_demuxer_fuzzer at this line:\r\n\r\nhttps://github.com/google/fuzzbench/blob/master/benchmarks/ffmpeg_ffmpeg_demuxer_fuzzer/Dockerfile#L17\r\n\r\nConsequently you cannot build this benchmark. I tried to fix it by using one of the two hashes, but the compilation does not work in any case (even if with two different errors).\n", "before_files": [{"content": "# Copyright 2020 Google LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\"\"\"Integration code for AFLplusplus fuzzer.\"\"\"\n\nimport os\nimport shutil\n\nfrom fuzzers.afl import fuzzer as afl_fuzzer\nfrom fuzzers import utils\n\n\ndef get_cmplog_build_directory(target_directory):\n    \"\"\"Return path to CmpLog target directory.\"\"\"\n    return os.path.join(target_directory, 'cmplog')\n\n\ndef get_uninstrumented_build_directory(target_directory):\n    \"\"\"Return path to CmpLog target directory.\"\"\"\n    return os.path.join(target_directory, 'uninstrumented')\n\n\ndef build(*args):  # pylint: disable=too-many-branches,too-many-statements\n    \"\"\"Build benchmark.\"\"\"\n    # BUILD_MODES is not already supported by fuzzbench, meanwhile we provide\n    # a default configuration.\n\n    build_modes = list(args)\n    if 'BUILD_MODES' in os.environ:\n        build_modes = os.environ['BUILD_MODES'].split(',')\n\n    # Placeholder comment.\n    build_directory = os.environ['OUT']\n\n    # If nothing was set this is the default:\n    if not build_modes:\n        build_modes = ['tracepc', 'cmplog', 'dict2file']\n\n    # For bug type benchmarks we have to instrument via native clang pcguard :(\n    build_flags = os.environ['CFLAGS']\n    if build_flags.find(\n            'array-bounds'\n    ) != -1 and 'qemu' not in build_modes and 'classic' not in build_modes:\n        build_modes[0] = 'native'\n\n    # Instrumentation coverage modes:\n    if 'lto' in build_modes:\n        os.environ['CC'] = '/afl/afl-clang-lto'\n        os.environ['CXX'] = '/afl/afl-clang-lto++'\n        edge_file = build_directory + '/aflpp_edges.txt'\n        os.environ['AFL_LLVM_DOCUMENT_IDS'] = edge_file\n        if os.path.isfile('/usr/local/bin/llvm-ranlib-13'):\n            os.environ['RANLIB'] = 'llvm-ranlib-13'\n            os.environ['AR'] = 'llvm-ar-13'\n            os.environ['AS'] = 'llvm-as-13'\n        elif os.path.isfile('/usr/local/bin/llvm-ranlib-12'):\n            os.environ['RANLIB'] = 'llvm-ranlib-12'\n            os.environ['AR'] = 'llvm-ar-12'\n            os.environ['AS'] = 'llvm-as-12'\n        else:\n            os.environ['RANLIB'] = 'llvm-ranlib'\n            os.environ['AR'] = 'llvm-ar'\n            os.environ['AS'] = 'llvm-as'\n    elif 'qemu' in build_modes:\n        os.environ['CC'] = 'clang'\n        os.environ['CXX'] = 'clang++'\n    elif 'gcc' in build_modes:\n        os.environ['CC'] = 'afl-gcc-fast'\n        os.environ['CXX'] = 'afl-g++-fast'\n    else:\n        os.environ['CC'] = '/afl/afl-clang-fast'\n        os.environ['CXX'] = '/afl/afl-clang-fast++'\n\n    print('AFL++ build: ')\n    print(build_modes)\n\n    if 'qemu' in build_modes or 'symcc' in build_modes:\n        os.environ['CFLAGS'] = ' '.join(utils.NO_SANITIZER_COMPAT_CFLAGS)\n        cxxflags = [utils.LIBCPLUSPLUS_FLAG] + utils.NO_SANITIZER_COMPAT_CFLAGS\n        os.environ['CXXFLAGS'] = ' '.join(cxxflags)\n\n    if 'tracepc' in build_modes or 'pcguard' in build_modes:\n        os.environ['AFL_LLVM_USE_TRACE_PC'] = '1'\n    elif 'classic' in build_modes:\n        os.environ['AFL_LLVM_INSTRUMENT'] = 'CLASSIC'\n    elif 'native' in build_modes:\n        os.environ['AFL_LLVM_INSTRUMENT'] = 'LLVMNATIVE'\n\n    # Instrumentation coverage options:\n    # Do not use a fixed map location (LTO only)\n    if 'dynamic' in build_modes:\n        os.environ['AFL_LLVM_MAP_DYNAMIC'] = '1'\n    # Use a fixed map location (LTO only)\n    if 'fixed' in build_modes:\n        os.environ['AFL_LLVM_MAP_ADDR'] = '0x10000'\n    # Generate an extra dictionary.\n    if 'dict2file' in build_modes or 'native' in build_modes:\n        os.environ['AFL_LLVM_DICT2FILE'] = build_directory + '/afl++.dict'\n    # Enable context sentitivity for LLVM mode (non LTO only)\n    if 'ctx' in build_modes:\n        os.environ['AFL_LLVM_CTX'] = '1'\n    # Enable N-gram coverage for LLVM mode (non LTO only)\n    if 'ngram2' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '2'\n    elif 'ngram3' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '3'\n    elif 'ngram4' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '4'\n    elif 'ngram5' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '5'\n    elif 'ngram6' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '6'\n    elif 'ngram7' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '7'\n    elif 'ngram8' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '8'\n    elif 'ngram16' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '16'\n    if 'ctx1' in build_modes:\n        os.environ['AFL_LLVM_CTX_K'] = '1'\n    elif 'ctx2' in build_modes:\n        os.environ['AFL_LLVM_CTX_K'] = '2'\n    elif 'ctx3' in build_modes:\n        os.environ['AFL_LLVM_CTX_K'] = '3'\n    elif 'ctx4' in build_modes:\n        os.environ['AFL_LLVM_CTX_K'] = '4'\n\n    # Only one of the following OR cmplog\n    # enable laf-intel compare splitting\n    if 'laf' in build_modes:\n        os.environ['AFL_LLVM_LAF_SPLIT_SWITCHES'] = '1'\n        os.environ['AFL_LLVM_LAF_SPLIT_COMPARES'] = '1'\n        os.environ['AFL_LLVM_LAF_SPLIT_FLOATS'] = '1'\n        if 'autodict' not in build_modes:\n            os.environ['AFL_LLVM_LAF_TRANSFORM_COMPARES'] = '1'\n\n    if 'eclipser' in build_modes:\n        os.environ['FUZZER_LIB'] = '/libStandaloneFuzzTarget.a'\n    else:\n        os.environ['FUZZER_LIB'] = '/libAFLDriver.a'\n\n    # Some benchmarks like lcms\n    # (see: https://github.com/mm2/Little-CMS/commit/ab1093539b4287c233aca6a3cf53b234faceb792#diff-f0e6d05e72548974e852e8e55dffc4ccR212)\n    # fail to compile if the compiler outputs things to stderr in unexpected\n    # cases. Prevent these failures by using AFL_QUIET to stop afl-clang-fast\n    # from writing AFL specific messages to stderr.\n    os.environ['AFL_QUIET'] = '1'\n    os.environ['AFL_MAP_SIZE'] = '2621440'\n\n    src = os.getenv('SRC')\n    work = os.getenv('WORK')\n\n    with utils.restore_directory(src), utils.restore_directory(work):\n        # Restore SRC to its initial state so we can build again without any\n        # trouble. For some OSS-Fuzz projects, build_benchmark cannot be run\n        # twice in the same directory without this.\n        utils.build_benchmark()\n\n    if 'cmplog' in build_modes and 'qemu' not in build_modes:\n\n        # CmpLog requires an build with different instrumentation.\n        new_env = os.environ.copy()\n        new_env['AFL_LLVM_CMPLOG'] = '1'\n\n        # For CmpLog build, set the OUT and FUZZ_TARGET environment\n        # variable to point to the new CmpLog build directory.\n        cmplog_build_directory = get_cmplog_build_directory(build_directory)\n        os.mkdir(cmplog_build_directory)\n        new_env['OUT'] = cmplog_build_directory\n        fuzz_target = os.getenv('FUZZ_TARGET')\n        if fuzz_target:\n            new_env['FUZZ_TARGET'] = os.path.join(cmplog_build_directory,\n                                                  os.path.basename(fuzz_target))\n\n        print('Re-building benchmark for CmpLog fuzzing target')\n        utils.build_benchmark(env=new_env)\n\n    if 'symcc' in build_modes:\n\n        symcc_build_directory = get_uninstrumented_build_directory(\n            build_directory)\n        os.mkdir(symcc_build_directory)\n\n        # symcc requires an build with different instrumentation.\n        new_env = os.environ.copy()\n        new_env['CC'] = '/symcc/build/symcc'\n        new_env['CXX'] = '/symcc/build/sym++'\n        new_env['SYMCC_OUTPUT_DIR'] = '/tmp'\n        new_env['CXXFLAGS'] = new_env['CXXFLAGS'].replace(\"-stlib=libc++\", \"\")\n        new_env['FUZZER_LIB'] = '/libfuzzer-harness.o'\n        new_env['OUT'] = symcc_build_directory\n        new_env['SYMCC_LIBCXX_PATH'] = \"/libcxx_native_build\"\n        new_env['SYMCC_NO_SYMBOLIC_INPUT'] = \"1\"\n        new_env['SYMCC_SILENT'] = \"1\"\n\n        # For CmpLog build, set the OUT and FUZZ_TARGET environment\n        # variable to point to the new CmpLog build directory.\n        new_env['OUT'] = symcc_build_directory\n        fuzz_target = os.getenv('FUZZ_TARGET')\n        if fuzz_target:\n            new_env['FUZZ_TARGET'] = os.path.join(symcc_build_directory,\n                                                  os.path.basename(fuzz_target))\n\n        print('Re-building benchmark for CmpLog fuzzing target')\n        utils.build_benchmark(env=new_env)\n\n    shutil.copy('/afl/afl-fuzz', build_directory)\n    if os.path.exists('/afl/afl-qemu-trace'):\n        shutil.copy('/afl/afl-qemu-trace', build_directory)\n    if os.path.exists('/aflpp_qemu_driver_hook.so'):\n        shutil.copy('/aflpp_qemu_driver_hook.so', build_directory)\n    if os.path.exists('/get_frida_entry.sh'):\n        shutil.copy('/afl/afl-frida-trace.so', build_directory)\n        shutil.copy('/get_frida_entry.sh', build_directory)\n\n\n# pylint: disable=too-many-arguments\ndef fuzz(input_corpus,\n         output_corpus,\n         target_binary,\n         flags=tuple(),\n         skip=False,\n         no_cmplog=False):  # pylint: disable=too-many-arguments\n    \"\"\"Run fuzzer.\"\"\"\n    # Calculate CmpLog binary path from the instrumented target binary.\n    target_binary_directory = os.path.dirname(target_binary)\n    cmplog_target_binary_directory = (\n        get_cmplog_build_directory(target_binary_directory))\n    target_binary_name = os.path.basename(target_binary)\n    cmplog_target_binary = os.path.join(cmplog_target_binary_directory,\n                                        target_binary_name)\n\n    afl_fuzzer.prepare_fuzz_environment(input_corpus)\n    # decomment this to enable libdislocator.\n    # os.environ['AFL_ALIGNED_ALLOC'] = '1' # align malloc to max_align_t\n    # os.environ['AFL_PRELOAD'] = '/afl/libdislocator.so'\n\n    flags = list(flags)\n\n    if os.path.exists('./afl++.dict'):\n        flags += ['-x', './afl++.dict']\n\n    # Move the following to skip for upcoming _double tests:\n    if os.path.exists(cmplog_target_binary) and no_cmplog is not False:\n        flags += ['-c', cmplog_target_binary]\n\n    if not skip:\n        os.environ['AFL_DISABLE_TRIM'] = \"1\"\n        # os.environ['AFL_FAST_CAL'] = '1'\n        os.environ['AFL_CMPLOG_ONLY_NEW'] = '1'\n        if 'ADDITIONAL_ARGS' in os.environ:\n            flags += os.environ['ADDITIONAL_ARGS'].split(' ')\n\n    afl_fuzzer.run_afl_fuzz(input_corpus,\n                            output_corpus,\n                            target_binary,\n                            additional_flags=flags)\n", "path": "fuzzers/aflplusplus/fuzzer.py"}], "after_files": [{"content": "# Copyright 2020 Google LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\"\"\"Integration code for AFLplusplus fuzzer.\"\"\"\n\nimport os\nimport shutil\n\nfrom fuzzers.afl import fuzzer as afl_fuzzer\nfrom fuzzers import utils\n\n\ndef get_cmplog_build_directory(target_directory):\n    \"\"\"Return path to CmpLog target directory.\"\"\"\n    return os.path.join(target_directory, 'cmplog')\n\n\ndef get_uninstrumented_build_directory(target_directory):\n    \"\"\"Return path to CmpLog target directory.\"\"\"\n    return os.path.join(target_directory, 'uninstrumented')\n\n\ndef build(*args):  # pylint: disable=too-many-branches,too-many-statements\n    \"\"\"Build benchmark.\"\"\"\n    # BUILD_MODES is not already supported by fuzzbench, meanwhile we provide\n    # a default configuration.\n\n    build_modes = list(args)\n    if 'BUILD_MODES' in os.environ:\n        build_modes = os.environ['BUILD_MODES'].split(',')\n\n    # Placeholder comment.\n    build_directory = os.environ['OUT']\n\n    # If nothing was set this is the default:\n    if not build_modes:\n        build_modes = ['tracepc', 'cmplog', 'dict2file']\n\n    # For bug type benchmarks we have to instrument via native clang pcguard :(\n    build_flags = os.environ['CFLAGS']\n    if build_flags.find(\n            'array-bounds'\n    ) != -1 and 'qemu' not in build_modes and 'classic' not in build_modes:\n        build_modes[0] = 'native'\n\n    # Instrumentation coverage modes:\n    if 'lto' in build_modes:\n        os.environ['CC'] = '/afl/afl-clang-lto'\n        os.environ['CXX'] = '/afl/afl-clang-lto++'\n        edge_file = build_directory + '/aflpp_edges.txt'\n        os.environ['AFL_LLVM_DOCUMENT_IDS'] = edge_file\n        if os.path.isfile('/usr/local/bin/llvm-ranlib-13'):\n            os.environ['RANLIB'] = 'llvm-ranlib-13'\n            os.environ['AR'] = 'llvm-ar-13'\n            os.environ['AS'] = 'llvm-as-13'\n        elif os.path.isfile('/usr/local/bin/llvm-ranlib-12'):\n            os.environ['RANLIB'] = 'llvm-ranlib-12'\n            os.environ['AR'] = 'llvm-ar-12'\n            os.environ['AS'] = 'llvm-as-12'\n        else:\n            os.environ['RANLIB'] = 'llvm-ranlib'\n            os.environ['AR'] = 'llvm-ar'\n            os.environ['AS'] = 'llvm-as'\n    elif 'qemu' in build_modes:\n        os.environ['CC'] = 'clang'\n        os.environ['CXX'] = 'clang++'\n    elif 'gcc' in build_modes:\n        os.environ['CC'] = 'afl-gcc-fast'\n        os.environ['CXX'] = 'afl-g++-fast'\n    else:\n        os.environ['CC'] = '/afl/afl-clang-fast'\n        os.environ['CXX'] = '/afl/afl-clang-fast++'\n\n    print('AFL++ build: ')\n    print(build_modes)\n\n    if 'qemu' in build_modes or 'symcc' in build_modes:\n        os.environ['CFLAGS'] = ' '.join(utils.NO_SANITIZER_COMPAT_CFLAGS)\n        cxxflags = [utils.LIBCPLUSPLUS_FLAG] + utils.NO_SANITIZER_COMPAT_CFLAGS\n        os.environ['CXXFLAGS'] = ' '.join(cxxflags)\n\n    if 'tracepc' in build_modes or 'pcguard' in build_modes:\n        os.environ['AFL_LLVM_USE_TRACE_PC'] = '1'\n    elif 'classic' in build_modes:\n        os.environ['AFL_LLVM_INSTRUMENT'] = 'CLASSIC'\n    elif 'native' in build_modes:\n        os.environ['AFL_LLVM_INSTRUMENT'] = 'LLVMNATIVE'\n\n    # Instrumentation coverage options:\n    # Do not use a fixed map location (LTO only)\n    if 'dynamic' in build_modes:\n        os.environ['AFL_LLVM_MAP_DYNAMIC'] = '1'\n    # Use a fixed map location (LTO only)\n    if 'fixed' in build_modes:\n        os.environ['AFL_LLVM_MAP_ADDR'] = '0x10000'\n    # Generate an extra dictionary.\n    if 'dict2file' in build_modes or 'native' in build_modes:\n        os.environ['AFL_LLVM_DICT2FILE'] = build_directory + '/afl++.dict'\n    # Enable context sentitivity for LLVM mode (non LTO only)\n    if 'ctx' in build_modes:\n        os.environ['AFL_LLVM_CTX'] = '1'\n    # Enable N-gram coverage for LLVM mode (non LTO only)\n    if 'ngram2' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '2'\n    elif 'ngram3' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '3'\n    elif 'ngram4' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '4'\n    elif 'ngram5' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '5'\n    elif 'ngram6' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '6'\n    elif 'ngram7' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '7'\n    elif 'ngram8' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '8'\n    elif 'ngram16' in build_modes:\n        os.environ['AFL_LLVM_NGRAM_SIZE'] = '16'\n    if 'ctx1' in build_modes:\n        os.environ['AFL_LLVM_CTX_K'] = '1'\n    elif 'ctx2' in build_modes:\n        os.environ['AFL_LLVM_CTX_K'] = '2'\n    elif 'ctx3' in build_modes:\n        os.environ['AFL_LLVM_CTX_K'] = '3'\n    elif 'ctx4' in build_modes:\n        os.environ['AFL_LLVM_CTX_K'] = '4'\n\n    # Only one of the following OR cmplog\n    # enable laf-intel compare splitting\n    if 'laf' in build_modes:\n        os.environ['AFL_LLVM_LAF_SPLIT_SWITCHES'] = '1'\n        os.environ['AFL_LLVM_LAF_SPLIT_COMPARES'] = '1'\n        os.environ['AFL_LLVM_LAF_SPLIT_FLOATS'] = '1'\n        if 'autodict' not in build_modes:\n            os.environ['AFL_LLVM_LAF_TRANSFORM_COMPARES'] = '1'\n\n    if 'eclipser' in build_modes:\n        os.environ['FUZZER_LIB'] = '/libStandaloneFuzzTarget.a'\n    else:\n        os.environ['FUZZER_LIB'] = '/libAFLDriver.a'\n\n    # Some benchmarks like lcms\n    # (see: https://github.com/mm2/Little-CMS/commit/ab1093539b4287c233aca6a3cf53b234faceb792#diff-f0e6d05e72548974e852e8e55dffc4ccR212)\n    # fail to compile if the compiler outputs things to stderr in unexpected\n    # cases. Prevent these failures by using AFL_QUIET to stop afl-clang-fast\n    # from writing AFL specific messages to stderr.\n    os.environ['AFL_QUIET'] = '1'\n    os.environ['AFL_MAP_SIZE'] = '2621440'\n\n    src = os.getenv('SRC')\n    work = os.getenv('WORK')\n\n    with utils.restore_directory(src), utils.restore_directory(work):\n        # Restore SRC to its initial state so we can build again without any\n        # trouble. For some OSS-Fuzz projects, build_benchmark cannot be run\n        # twice in the same directory without this.\n        utils.build_benchmark()\n\n    if 'cmplog' in build_modes and 'qemu' not in build_modes:\n\n        # CmpLog requires an build with different instrumentation.\n        new_env = os.environ.copy()\n        new_env['AFL_LLVM_CMPLOG'] = '1'\n\n        # For CmpLog build, set the OUT and FUZZ_TARGET environment\n        # variable to point to the new CmpLog build directory.\n        cmplog_build_directory = get_cmplog_build_directory(build_directory)\n        os.mkdir(cmplog_build_directory)\n        new_env['OUT'] = cmplog_build_directory\n        fuzz_target = os.getenv('FUZZ_TARGET')\n        if fuzz_target:\n            new_env['FUZZ_TARGET'] = os.path.join(cmplog_build_directory,\n                                                  os.path.basename(fuzz_target))\n\n        print('Re-building benchmark for CmpLog fuzzing target')\n        utils.build_benchmark(env=new_env)\n\n    if 'symcc' in build_modes:\n\n        symcc_build_directory = get_uninstrumented_build_directory(\n            build_directory)\n        os.mkdir(symcc_build_directory)\n\n        # symcc requires an build with different instrumentation.\n        new_env = os.environ.copy()\n        new_env['CC'] = '/symcc/build/symcc'\n        new_env['CXX'] = '/symcc/build/sym++'\n        new_env['SYMCC_OUTPUT_DIR'] = '/tmp'\n        new_env['CXXFLAGS'] = new_env['CXXFLAGS'].replace(\"-stlib=libc++\", \"\")\n        new_env['FUZZER_LIB'] = '/libfuzzer-harness.o'\n        new_env['OUT'] = symcc_build_directory\n        new_env['SYMCC_LIBCXX_PATH'] = \"/libcxx_native_build\"\n        new_env['SYMCC_NO_SYMBOLIC_INPUT'] = \"1\"\n        new_env['SYMCC_SILENT'] = \"1\"\n\n        # For CmpLog build, set the OUT and FUZZ_TARGET environment\n        # variable to point to the new CmpLog build directory.\n        new_env['OUT'] = symcc_build_directory\n        fuzz_target = os.getenv('FUZZ_TARGET')\n        if fuzz_target:\n            new_env['FUZZ_TARGET'] = os.path.join(symcc_build_directory,\n                                                  os.path.basename(fuzz_target))\n\n        print('Re-building benchmark for CmpLog fuzzing target')\n        utils.build_benchmark(env=new_env)\n\n    shutil.copy('/afl/afl-fuzz', build_directory)\n    if os.path.exists('/afl/afl-qemu-trace'):\n        shutil.copy('/afl/afl-qemu-trace', build_directory)\n    if os.path.exists('/aflpp_qemu_driver_hook.so'):\n        shutil.copy('/aflpp_qemu_driver_hook.so', build_directory)\n    if os.path.exists('/get_frida_entry.sh'):\n        shutil.copy('/afl/afl-frida-trace.so', build_directory)\n        shutil.copy('/get_frida_entry.sh', build_directory)\n\n\n# pylint: disable=too-many-arguments\ndef fuzz(input_corpus,\n         output_corpus,\n         target_binary,\n         flags=tuple(),\n         skip=False,\n         no_cmplog=False):  # pylint: disable=too-many-arguments\n    \"\"\"Run fuzzer.\"\"\"\n    # Calculate CmpLog binary path from the instrumented target binary.\n    target_binary_directory = os.path.dirname(target_binary)\n    cmplog_target_binary_directory = (\n        get_cmplog_build_directory(target_binary_directory))\n    target_binary_name = os.path.basename(target_binary)\n    cmplog_target_binary = os.path.join(cmplog_target_binary_directory,\n                                        target_binary_name)\n\n    afl_fuzzer.prepare_fuzz_environment(input_corpus)\n    # decomment this to enable libdislocator.\n    # os.environ['AFL_ALIGNED_ALLOC'] = '1' # align malloc to max_align_t\n    # os.environ['AFL_PRELOAD'] = '/afl/libdislocator.so'\n\n    flags = list(flags)\n\n    if os.path.exists('./afl++.dict'):\n        flags += ['-x', './afl++.dict']\n\n    # Move the following to skip for upcoming _double tests:\n    if os.path.exists(cmplog_target_binary) and no_cmplog is False:\n        flags += ['-c', cmplog_target_binary]\n\n    if not skip:\n        os.environ['AFL_DISABLE_TRIM'] = \"1\"\n        # os.environ['AFL_FAST_CAL'] = '1'\n        os.environ['AFL_CMPLOG_ONLY_NEW'] = '1'\n        if 'ADDITIONAL_ARGS' in os.environ:\n            flags += os.environ['ADDITIONAL_ARGS'].split(' ')\n\n    afl_fuzzer.run_afl_fuzz(input_corpus,\n                            output_corpus,\n                            target_binary,\n                            additional_flags=flags)\n", "path": "fuzzers/aflplusplus/fuzzer.py"}]}