Skip to content

Commit ff14b13

Browse files
author
John Andersen
committed
gnutls test and improved no cves error messages in TestScanner
Signed-off-by: John Andersen <[email protected]>
1 parent d2777d8 commit ff14b13

File tree

4 files changed

+67
-19
lines changed

4 files changed

+67
-19
lines changed

cve_bin_tool/checkers/gnutls.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,33 @@
44
References:
55
https://www.cvedetails.com/vulnerability-list/vendor_id-72/product_id-4433/GNU-Gnutls.html
66
"""
7+
import os
78
from ..util import regex_find
89

10+
911
def get_version(lines, filename):
1012
"""
1113
returns version information for gnutls found in given file.
12-
Verfies using the tools gnutls-cli
14+
Verfies using the tools gnutls-cli
1315
Verifies using the libraries libgnutls.so and libgnutls-dane.so
1416
17+
VPkg: gnu, gnutls
1518
VPkg: gnutls, gnutls
1619
"""
17-
regex = [r"gnutls-cli ([3]+\.[0-9]+\.[0-9]+)"]
18-
version_info = dict()
19-
if filename[::-1].startswith(("gnutls-cli")[::-1]):
20-
version_info["is_or_contains"] = "is"
21-
if filename[::-1].startswith(("gnutls-serv")[::-1]):
22-
version_info["is_or_contains"] = "is"
20+
regex = [r"gnutls-cli ([0-9]+\.[0-9]+\.[0-9]+)"]
2321

24-
if "is_or_contains" in version_info:
25-
version_info["modulename"] = "gnutls-cli"
26-
version_info["version"] = regex_find(lines, *regex)
27-
elif "libgnutls.so" in filename:
28-
version_info["is_or_contains"] = "is"
29-
elif "libgnutls-dane.so" in filename:
30-
version_info["is_or_contains"] = "is"
22+
for modulename, binary_names in (
23+
{
24+
"gnutls-serv": ["gnutls-serv"],
25+
"gnutls-cli": ["gnutls-cli", "libgnutls.so", "libgnutls-dane.so"],
26+
}
27+
).items():
28+
for check in binary_names:
29+
if check in os.path.split(filename)[-1]:
30+
return {
31+
"is_or_contains": "is",
32+
"modulename": modulename,
33+
"version": regex_find(lines, *regex),
34+
}
3135

32-
return version_info
36+
return {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
printf("This program is designed to test the cve-bin-tool checker.");
5+
printf("It outputs a few strings normally associated with gnutls-cli 2.3.11");
6+
printf("They appear below this line.");
7+
printf("------------------");
8+
printf("gnutls-cli 2.3.11");
9+
10+
return 0;
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
printf("This program is designed to test the cve-bin-tool checker.");
5+
printf("It outputs a few strings normally associated with gnutls-serv 2.3.11");
6+
printf("They appear below this line.");
7+
printf("------------------");
8+
printf("gnutls-serv 2.3.11");
9+
10+
return 0;
11+
}

test/test_scanner.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ def _binary_test(self, binary, package, version, are_in, not_in):
9191
# Run the scan
9292
cves = self.scan_file(binary)
9393
# Make sure the package and version are in the results
94-
self.assertIn(package, cves)
95-
self.assertIn(version, cves[package])
94+
self.assertIn(package, list(cves.keys()))
95+
self.assertIn(version, list(cves[package].keys()))
9696
# Test for CVEs known in this version
9797
for ensure_in in are_in:
98-
self.assertIn(ensure_in, cves[package][version])
98+
self.assertIn(ensure_in, list(cves[package][version].keys()))
9999
# Test for a CVE that is not in this version
100100
for ensure_out in not_in:
101-
self.assertNotIn(ensure_out, cves[package][version])
101+
self.assertNotIn(ensure_out, list(cves[package][version].keys()))
102102

103103
def _file_test(self, url, filename, package, version):
104104
""" Helper function to get a file (presumed to be a real copy
@@ -245,6 +245,28 @@ def test_ffmpeg_4_1_4(self):
245245
],
246246
)
247247

248+
def test_gnutls_2_3_11(self):
249+
"""Scanning test-gnutls-{binary}-2.3.11.out"""
250+
for binary in ["cli", "serv"]:
251+
with self.subTest(binary=binary):
252+
self._binary_test(
253+
"test-gnutls-{}-2.3.11.out".format(binary),
254+
"gnutls-cli",
255+
"2.3.11",
256+
[
257+
# known cves in 2.3.11
258+
"CVE-2008-1948",
259+
"CVE-2008-1949",
260+
"CVE-2008-1950",
261+
],
262+
[
263+
# an older cve from before 2.3.11
264+
"CVE-2004-2531",
265+
# an newer cve from after 2.3.11
266+
"CVE-2017-7869",
267+
],
268+
)
269+
248270
def test_jpeg_2_0_1(self):
249271
"""Scanning test-libjpeg-turbo-2.0.1"""
250272
self._binary_test(

0 commit comments

Comments
 (0)