Skip to content

Commit 2631a97

Browse files
committed
Find fuzz target binary under build.out
1 parent cd6dc02 commit 2631a97

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

infra/build/functions/target_experiment.py

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030

3131
def run_experiment(project_name, target_name, args, output_path,
3232
build_output_path, upload_corpus_path, upload_coverage_path,
33-
experiment_name, local_artifact_path,
34-
upload_reproducer_path):
33+
experiment_name, upload_reproducer_path):
3534
config = build_project.Config(testing=True,
3635
test_image_suffix='',
3736
repo=build_project.DEFAULT_OSS_FUZZ_REPO,
@@ -75,10 +74,10 @@ def run_experiment(project_name, target_name, args, output_path,
7574
local_output_path = '/workspace/output.log'
7675
local_corpus_path_base = '/workspace/corpus'
7776
local_corpus_path = os.path.join(local_corpus_path_base, target_name)
78-
local_target_path = os.path.join(build.out, target_name)
77+
default_target_path = os.path.join(build.out, target_name)
78+
local_target_dir = os.path.join(build.out, 'target')
7979
local_corpus_zip_path = '/workspace/corpus/corpus.zip'
80-
if not local_artifact_path:
81-
local_artifact_path = os.path.join(build.out, 'artifacts')
80+
local_artifact_path = os.path.join(build.out, 'artifacts')
8281
fuzzer_args = ' '.join(args + [f'-artifact_prefix={local_artifact_path}'])
8382

8483
env = build_project.get_env(project_yaml['language'], build)
@@ -94,6 +93,7 @@ def run_experiment(project_name, target_name, args, output_path,
9493
'bash',
9594
'-c',
9695
(f'mkdir -p {local_corpus_path} && '
96+
f'mkdir -p {local_target_dir} && '
9797
f'mkdir -p {local_artifact_path} && '
9898
f'run_fuzzer {target_name} {fuzzer_args} '
9999
f'|& tee {local_output_path} || true'),
@@ -120,31 +120,38 @@ def run_experiment(project_name, target_name, args, output_path,
120120
],
121121
})
122122

123-
# Upload binary.
124-
steps.append({
125-
'name':
126-
'gcr.io/cloud-builders/gsutil',
127-
'entrypoint':
128-
'/bin/bash',
129-
'args': [
130-
'-c',
131-
(f'gsutil cp {local_target_path} '
132-
f'{upload_reproducer_path}/{target_name} || true'),
133-
],
134-
})
123+
if upload_reproducer_path:
124+
# Upload binary. First copy the binary directly from default_target_path,
125+
# if that fails, find it under build out dir and copy to local_target_dir.
126+
# If either succeeds, then upload it to bucket.
127+
# If multiple files are found, suffix them and upload them all.
128+
steps.append({
129+
'name':
130+
'gcr.io/cloud-builders/gsutil',
131+
'entrypoint':
132+
'/bin/bash',
133+
'args': [
134+
'-c',
135+
(f'cp {default_target_path} {local_target_dir} 2>/dev/null || '
136+
f'find {build.out} -type f -name {target_name} -exec bash -c '
137+
f'\'cp "$0" "{local_target_dir}/$(basename "$0")_$(date +%s%N)"\' '
138+
f'{{}} \\; && gsutil cp -r {local_target_dir} '
139+
f'{upload_reproducer_path}/{target_name} || true'),
140+
],
141+
})
135142

136-
# Upload reproducer.
137-
steps.append({
138-
'name':
139-
'gcr.io/cloud-builders/gsutil',
140-
'entrypoint':
141-
'/bin/bash',
142-
'args': [
143-
'-c',
144-
(f'gsutil -m cp -r {local_artifact_path} {upload_reproducer_path} || '
145-
'true'),
146-
],
147-
})
143+
# Upload reproducer.
144+
steps.append({
145+
'name':
146+
'gcr.io/cloud-builders/gsutil',
147+
'entrypoint':
148+
'/bin/bash',
149+
'args': [
150+
'-c',
151+
(f'gsutil -m cp -r {local_artifact_path} {upload_reproducer_path} '
152+
'|| true'),
153+
],
154+
})
148155

149156
# Build for coverage.
150157
build = build_project.Build('libfuzzer', 'coverage', 'x86_64')
@@ -245,24 +252,21 @@ def main():
245252
required=True,
246253
help='GCS location to upload corpus.')
247254
parser.add_argument('--upload_reproducer',
248-
required=True,
255+
required=False,
256+
default='',
249257
help='GCS location to upload reproducer.')
250258
parser.add_argument('--upload_coverage',
251259
required=True,
252260
help='GCS location to upload coverage data.')
253261
parser.add_argument('--experiment_name',
254262
required=True,
255263
help='Experiment name.')
256-
parser.add_argument('--local_artifact_path',
257-
required=False,
258-
default='',
259-
help='libFuzzer local artifact directory.')
260264
args = parser.parse_args()
261265

262266
run_experiment(args.project, args.target, args.args, args.upload_output_log,
263267
args.upload_build_log, args.upload_corpus,
264268
args.upload_coverage, args.experiment_name,
265-
args.local_artifact_path, args.upload_reproducer)
269+
args.upload_reproducer)
266270

267271

268272
if __name__ == '__main__':

0 commit comments

Comments
 (0)