Skip to content

Commit 8f8190e

Browse files
authored
Import data from OSS-Fuzz (#897)
Add OSSFuzzImprover to IMPROVERS_REGISTRY Fix oss-fuzz test ( add weakness in expected test file ) Add oss-fuzz tests Import data from oss_fuzz using osv format Resolve merge conflicts Signed-off-by: ziadhany <[email protected]>
1 parent d8cdaf4 commit 8f8190e

File tree

9 files changed

+196
-0
lines changed

9 files changed

+196
-0
lines changed

vulnerabilities/importers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from vulnerabilities.importers import npm
2626
from vulnerabilities.importers import nvd
2727
from vulnerabilities.importers import openssl
28+
from vulnerabilities.importers import oss_fuzz
2829
from vulnerabilities.importers import postgresql
2930
from vulnerabilities.importers import project_kb_msr2019
3031
from vulnerabilities.importers import pypa
@@ -65,6 +66,7 @@
6566
ubuntu_usn.UbuntuUSNImporter,
6667
fireeye.FireyeImporter,
6768
apache_kafka.ApacheKafkaImporter,
69+
oss_fuzz.OSSFuzzImporter,
6870
]
6971

7072
IMPORTERS_REGISTRY = {x.qualified_name: x for x in IMPORTERS_REGISTRY}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
from pathlib import Path
11+
from typing import Iterable
12+
13+
import saneyaml
14+
15+
from vulnerabilities.importer import AdvisoryData
16+
from vulnerabilities.importer import Importer
17+
from vulnerabilities.importers.osv import parse_advisory_data
18+
19+
logger = logging.getLogger(__name__)
20+
21+
22+
class OSSFuzzImporter(Importer):
23+
license_url = "https://github.com/google/oss-fuzz-vulns/blob/main/LICENSE"
24+
spdx_license_expression = "CC-BY-4.0"
25+
url = "git+https://github.com/google/oss-fuzz-vulns"
26+
27+
def advisory_data(self) -> Iterable[AdvisoryData]:
28+
try:
29+
self.clone(repo_url=self.url)
30+
path = Path(self.vcs_response.dest_dir) / "vulns"
31+
for file in path.glob("**/*.yaml"):
32+
with open(file) as f:
33+
yaml_data = saneyaml.load(f.read())
34+
yield parse_advisory_data(yaml_data, supported_ecosystem="oss-fuzz")
35+
finally:
36+
if self.vcs_response:
37+
self.vcs_response.delete()

vulnerabilities/improvers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
valid_versions.IstioImprover,
2323
valid_versions.DebianOvalImprover,
2424
valid_versions.UbuntuOvalImprover,
25+
valid_versions.OSSFuzzImprover,
2526
]
2627

2728
IMPROVERS_REGISTRY = {x.qualified_name: x for x in IMPROVERS_REGISTRY}

vulnerabilities/improvers/valid_versions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from vulnerabilities.importers.istio import IstioImporter
3636
from vulnerabilities.importers.nginx import NginxImporter
3737
from vulnerabilities.importers.npm import NpmImporter
38+
from vulnerabilities.importers.oss_fuzz import OSSFuzzImporter
3839
from vulnerabilities.importers.ubuntu import UbuntuImporter
3940
from vulnerabilities.improver import MAX_CONFIDENCE
4041
from vulnerabilities.improver import Improver
@@ -477,3 +478,8 @@ class DebianOvalImprover(ValidVersionImprover):
477478
class UbuntuOvalImprover(ValidVersionImprover):
478479
importer = UbuntuImporter
479480
ignorable_versions = []
481+
482+
483+
class OSSFuzzImprover(ValidVersionImprover):
484+
importer = OSSFuzzImporter
485+
ignorable_versions = []
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
id: OSV-2021-933
2+
summary: Heap-buffer-overflow in print_mac
3+
details: |
4+
OSS-Fuzz report: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35887
5+
6+
```
7+
Crash type: Heap-buffer-overflow WRITE 4
8+
Crash state:
9+
print_mac
10+
log_packet
11+
dhcp_reply
12+
```
13+
modified: '2022-04-13T03:04:31.143462Z'
14+
published: '2021-07-08T00:01:26.369555Z'
15+
references:
16+
- type: REPORT
17+
url: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35887
18+
affected:
19+
- package:
20+
name: dnsmasq
21+
ecosystem: OSS-Fuzz
22+
ranges:
23+
- type: GIT
24+
repo: git://thekelleys.org.uk/dnsmasq.git
25+
events:
26+
- introduced: 96f6444958c29a670f4254722d787f328153605c
27+
- fixed: d242cbffa4f20c9f7472f79b3a9e47008b6fe77c
28+
versions:
29+
- v2.86
30+
- v2.86rc1
31+
- v2.86rc2
32+
- v2.86rc3
33+
- v2.86test5
34+
- v2.86test6
35+
- v2.86test7
36+
- v2.87test1
37+
- v2.87test2
38+
- v2.87test3
39+
- v2.87test4
40+
ecosystem_specific:
41+
severity: HIGH
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"aliases": [
3+
"OSV-2021-933"
4+
],
5+
"summary": "Heap-buffer-overflow in print_mac\nOSS-Fuzz report: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35887\n\n```\nCrash type: Heap-buffer-overflow WRITE 4\nCrash state:\nprint_mac\nlog_packet\ndhcp_reply\n```",
6+
"affected_packages": [
7+
8+
],
9+
"references": [
10+
{
11+
"reference_id": "",
12+
"url": "https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35887",
13+
"severities": [
14+
15+
]
16+
}
17+
],
18+
"date_published": "2021-07-08T00:01:26.369555+00:00",
19+
"weaknesses": []
20+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
id: OSV-2022-145
2+
summary: Heap-buffer-overflow in print_mac
3+
details: |
4+
OSS-Fuzz report: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44581
5+
6+
```
7+
Crash type: Heap-buffer-overflow WRITE 4
8+
Crash state:
9+
print_mac
10+
log_packet
11+
dhcp_reply
12+
```
13+
modified: '2022-04-13T03:04:31.179893Z'
14+
published: '2022-02-13T00:01:27.883603Z'
15+
references:
16+
- type: REPORT
17+
url: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44581
18+
affected:
19+
- package:
20+
name: dnsmasq
21+
ecosystem: OSS-Fuzz
22+
purl: pkg:generic/dnsmasq
23+
ranges:
24+
- type: GIT
25+
repo: git://thekelleys.org.uk/dnsmasq.git
26+
events:
27+
- introduced: e426c2d3bc182d790f83039b77a09d55230ca71f
28+
- fixed: 03345ecefeb0d82e3c3a4c28f27c3554f0611b39
29+
versions:
30+
- v2.87test8
31+
ecosystem_specific:
32+
severity: HIGH
33+
schema_version: 1.2.0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"aliases": [
3+
"OSV-2022-145"
4+
],
5+
"summary": "Heap-buffer-overflow in print_mac\nOSS-Fuzz report: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44581\n\n```\nCrash type: Heap-buffer-overflow WRITE 4\nCrash state:\nprint_mac\nlog_packet\ndhcp_reply\n```",
6+
"affected_packages": [
7+
8+
],
9+
"references": [
10+
{
11+
"reference_id": "",
12+
"url": "https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44581",
13+
"severities": [
14+
15+
]
16+
}
17+
],
18+
"date_published": "2022-02-13T00:01:27.883603+00:00",
19+
"weaknesses": []
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 os
10+
from unittest import TestCase
11+
12+
import saneyaml
13+
14+
from vulnerabilities.importers.osv import parse_advisory_data
15+
from vulnerabilities.tests import util_tests
16+
17+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
18+
TEST_DATA = os.path.join(BASE_DIR, "test_data/oss_fuzz")
19+
20+
21+
class TestOSSFuzzImporter(TestCase):
22+
def test_to_advisories1(self):
23+
with open(os.path.join(TEST_DATA, "oss-fuzz-data1.yaml")) as f:
24+
mock_response = saneyaml.load(f)
25+
expected_file = os.path.join(TEST_DATA, "oss-fuzz-data1.yaml-expected.json")
26+
imported_data = parse_advisory_data(mock_response, "oss-fuzz")
27+
result = imported_data.to_dict()
28+
util_tests.check_results_against_json(result, expected_file)
29+
30+
def test_to_advisorie2(self):
31+
with open(os.path.join(TEST_DATA, "oss-fuzz-data2.yaml")) as f:
32+
mock_response = saneyaml.load(f)
33+
expected_file = os.path.join(TEST_DATA, "oss-fuzz-data2.yaml-expected.json")
34+
imported_data = parse_advisory_data(mock_response, "oss-fuzz")
35+
result = imported_data.to_dict()
36+
util_tests.check_results_against_json(result, expected_file)

0 commit comments

Comments
 (0)