This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathoss-fuzz-target.py
executable file
·91 lines (74 loc) · 2.65 KB
/
oss-fuzz-target.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
#
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import logging
import os
import sys
import tempfile
from subprocess import PIPE, CalledProcessError, check_call # nosec
from typing import List, Optional
from onefuzztypes.models import NotificationConfig
from onefuzztypes.primitives import PoolName
from onefuzz.api import Command, Onefuzz
from onefuzz.cli import execute_api
SANITIZERS = ["address", "dataflow", "memory", "undefined"]
class Ossfuzz(Command):
def build(self, project: str, sanitizer: str) -> None:
"""Build the latest oss-fuzz target"""
self.logger.info("building %s:%s", project, sanitizer)
cmd = [
"docker",
"run",
"--rm",
"-ti",
"-e",
"SANITIZER=%s" % sanitizer,
"--mount",
"src=%s,target=/out,type=bind" % os.getcwd(),
"gcr.io/oss-fuzz/%s" % project,
"compile",
]
check_call(cmd, stderr=PIPE, stdout=PIPE)
def fuzz(
self,
project: str,
build: str,
pool: PoolName,
sanitizers: Optional[List[str]] = None,
notification_config: Optional[NotificationConfig] = None,
) -> None:
"""Build & Launch all of the libFuzzer targets for a given project"""
if sanitizers is None:
sanitizers = SANITIZERS
for sanitizer in sanitizers:
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
try:
self.build(project, sanitizer)
except CalledProcessError:
self.logger.warning("building %s:%s failed", project, sanitizer)
continue
self.logger.info("launching %s:%s build:%s", project, sanitizer, build)
self.onefuzz.template.ossfuzz.libfuzzer(
project,
"%s:%s" % (sanitizer, build),
pool,
max_target_count=0,
sync_inputs=True,
notification_config=notification_config,
)
def stop(self, project: str) -> None:
for job in self.onefuzz.jobs.list():
if job.config.project != project:
continue
if job.config.build != "base":
continue
self.logger.info("stopping %s: %s", job.job_id, job.state)
self.onefuzz.jobs.delete(job.job_id)
def main() -> int:
return execute_api(
Ossfuzz(Onefuzz(), logging.getLogger("ossfuzz")), [Command], "0.0.1"
)
if __name__ == "__main__":
sys.exit(main())