Skip to content

Commit 8d615e6

Browse files
committed
Import data from oss_fuzz using osv format
Resolve merge conflicts Signed-off-by: ziad <ziadhany2016@gmail.com>
1 parent 6b0a4c2 commit 8d615e6

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

vulnerabilities/importers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from vulnerabilities.importers import npm
1818
from vulnerabilities.importers import nvd
1919
from vulnerabilities.importers import openssl
20+
from vulnerabilities.importers import oss_fuzz
2021
from vulnerabilities.importers import postgresql
2122
from vulnerabilities.importers import pypa
2223
from vulnerabilities.importers import pysec
@@ -39,6 +40,7 @@
3940
ubuntu.UbuntuImporter,
4041
debian_oval.DebianOvalImporter,
4142
npm.NpmImporter,
43+
oss_fuzz.OSS_FuzzImporter,
4244
]
4345

4446
IMPORTERS_REGISTRY = {x.qualified_name: x for x in IMPORTERS_REGISTRY}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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/nexB/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
import logging
10+
import os
11+
from typing import Iterable
12+
13+
import saneyaml
14+
from fetchcode.vcs.git import fetch_via_git
15+
16+
from vulnerabilities.importer import AdvisoryData
17+
from vulnerabilities.importer import Importer
18+
from vulnerabilities.importers.osv import parse_advisory_data
19+
20+
logger = logging.getLogger(__name__)
21+
22+
23+
class OSS_FuzzImporter(Importer):
24+
license_url = "https://github.com/google/oss-fuzz-vulns/blob/main/LICENSE"
25+
spdx_license_expression = "CC-BY-4.0"
26+
url = "git+https://github.com/google/oss-fuzz-vulns"
27+
28+
def advisory_data(self) -> Iterable[AdvisoryData]:
29+
for file in fork_and_get_files(self.url):
30+
yield parse_advisory_data(file, supported_ecosystem="oss-fuzz")
31+
32+
33+
class ForkError(Exception):
34+
pass
35+
36+
37+
def fork_and_get_files(url) -> dict:
38+
"""
39+
Fetch the github repository and go to vulns directory ,
40+
then open directories one by one and return a file .
41+
"""
42+
try:
43+
fork_directory = fetch_via_git(url=url)
44+
except Exception as e:
45+
logger.error(f"Can't clone url {url}")
46+
raise ForkError(url) from e
47+
48+
advisory_dirs = os.path.join(fork_directory.dest_dir, "vulns")
49+
for root, _, files in os.walk(advisory_dirs):
50+
for file in files:
51+
if not file.endswith(".yaml"):
52+
logger.warning(f"unsupported file {file}")
53+
else:
54+
with open(os.path.join(root, file), "r") as f:
55+
yield saneyaml.load(f.read())

0 commit comments

Comments
 (0)