Skip to content

Commit 814d19b

Browse files
committed
Add OSS Fuzz importer
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 3d34e55 commit 814d19b

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

vulnerabilities/importers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from vulnerabilities.pipelines.v2_importers import pysec_importer as pysec_importer_v2
5454
from vulnerabilities.pipelines.v2_importers import vulnrichment_importer as vulnrichment_importer_v2
5555
from vulnerabilities.pipelines.v2_importers import xen_importer as xen_importer_v2
56+
from vulnerabilities.pipelines.v2_importers import oss_fuzz as oss_fuzz_v2
5657
from vulnerabilities.utils import create_registry
5758

5859
IMPORTERS_REGISTRY = create_registry(
@@ -67,6 +68,7 @@
6768
pysec_importer_v2.PyPIImporterPipeline,
6869
xen_importer_v2.XenImporterPipeline,
6970
curl_importer_v2.CurlImporterPipeline,
71+
oss_fuzz_v2.OSSFuzzImporterPipeline,
7072
nvd_importer.NVDImporterPipeline,
7173
github_importer.GitHubAPIImporterPipeline,
7274
gitlab_importer.GitLabImporterPipeline,
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
import logging
10+
from pathlib import Path
11+
from typing import Iterable
12+
13+
import saneyaml
14+
15+
from vulnerabilities.importer import AdvisoryData
16+
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2
17+
from vulnerabilities.utils import get_advisory_url
18+
from fetchcode.vcs import fetch_via_vcs
19+
20+
logger = logging.getLogger(__name__)
21+
22+
23+
class OSSFuzzImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
24+
pipeline_id = "oss_fuzz_importer_v2"
25+
spdx_license_expression = "CC-BY-4.0"
26+
license_url = "https://github.com/google/oss-fuzz-vulns/blob/main/LICENSE"
27+
repo_url = "git+https://github.com/google/oss-fuzz-vulns"
28+
unfurl_version_ranges = True
29+
30+
@classmethod
31+
def steps(cls):
32+
return (
33+
cls.clone,
34+
cls.collect_and_store_advisories,
35+
cls.clean_downloads,
36+
)
37+
38+
def clone(self):
39+
self.log(f"Cloning `{self.repo_url}`")
40+
self.vcs_response = fetch_via_vcs(self.repo_url)
41+
42+
def advisories_count(self):
43+
vulns_directory = Path(self.vcs_response.dest_dir) / "vulns"
44+
return sum(1 for _ in vulns_directory.rglob("*.yaml"))
45+
46+
def collect_advisories(self) -> Iterable[AdvisoryData]:
47+
from vulnerabilities.importers.osv import parse_advisory_data_v2
48+
49+
base_directory = Path(self.vcs_response.dest_dir)
50+
vulns_directory = base_directory / "vulns"
51+
52+
for advisory in vulns_directory.rglob("*.yaml"):
53+
advisory_url = get_advisory_url(
54+
file=advisory,
55+
base_path=base_directory,
56+
url="https://github.com/google/oss-fuzz-vulns/blob/main/",
57+
)
58+
advisory_text = advisory.read_text()
59+
advisory_dict = saneyaml.load(advisory_text)
60+
yield parse_advisory_data_v2(
61+
raw_data=advisory_dict,
62+
supported_ecosystems=["generic"],
63+
advisory_url=advisory_url,
64+
advisory_text=advisory_text,
65+
)
66+
67+
def clean_downloads(self):
68+
if self.vcs_response:
69+
self.log(f"Removing cloned repository")
70+
self.vcs_response.delete()
71+
72+
def on_failure(self):
73+
self.clean_downloads()

0 commit comments

Comments
 (0)