Skip to content

Commit 24a9516

Browse files
committed
Fix some bug risks and quality issues
Changes: - Fixed mutable default arguments used in `cve_bin_tool/csv2cve.py` and `cve_bin_tool/cli.py` - Removed unused imports in `cve_bin_tool/cli.py`, `cve_bin_tool/checkers/openssh.py` and `cve_bin_tool/NVDAutoUpdate.py` - Use raw strings in `cve_bin_tool/checkers/openssh.py`, `cve_bin_tool/NVDAutoUpdate.py` and `cve_bin_tool/checkers/expat.py` - Replaced `range(len(..))` with `enumerate()` in `cve_bin_tool/cli.py`
1 parent 5ccffc0 commit 24a9516

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

cve_bin_tool/NVDAutoUpdate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,9 @@ def find_curl_list(
190190
):
191191
""" Extract curl data """
192192
# import urllib.request
193-
import re
194193

195194
cve_pattern = re.compile('name=(CVE-[^"]*)')
196-
nextver_pattern = re.compile("the subsequent release: ([\d.]+)")
195+
nextver_pattern = re.compile(r"the subsequent release: ([\d.]+)")
197196

198197
# Start with version 6.0 since that's currently first
199198
version = "6.0"

cve_bin_tool/checkers/expat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python3
22
# pylint: disable=anomalous-backslash-in-string, invalid-name
3-
"""
3+
r"""
44
CVE checker for libexpat
55
66
References:

cve_bin_tool/checkers/openssh.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
References:
77
https://www.cvedetails.com/product/585/Openbsd-Openssh.html?vendor_id=97
88
"""
9-
from ..util import regex_find
10-
11-
import sys, re
9+
import re
1210

1311

1412
def get_version(lines, filename):
@@ -17,7 +15,7 @@ def get_version(lines, filename):
1715
1816
VPkg: openbsd, openssh
1917
"""
20-
regex = re.compile("OpenSSH_([0-9]+\.[0-9]+[0-9a-z\s]*)")
18+
regex = re.compile(r"OpenSSH_([0-9]+\.[0-9]+[0-9a-z\s]*)")
2119
version_info = dict()
2220

2321
# determine version

cve_bin_tool/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import sys
1616
import os
1717
import csv
18-
import glob
1918
import platform
2019
import subprocess
2120
import logging
@@ -120,7 +119,7 @@ def get_cves(self, vendor_package_pairs, vers):
120119
"""
121120
cves = defaultdict(list)
122121

123-
for i in range(len(vendor_package_pairs)):
122+
for i, _ in enumerate(vendor_package_pairs):
124123
vendor_package_pairs[i] = tuple(vendor_package_pairs[i])[:2] + (
125124
"%" + str(vers) + "%",
126125
)
@@ -290,8 +289,11 @@ def output_cves(outfile, modules, include_details=False):
290289
writer.writerow(row)
291290

292291

293-
def main(argv=sys.argv, outfile=sys.stdout):
292+
def main(argv=None, outfile=sys.stdout):
294293
""" Scan a binary file for certain open source libraries that may have CVEs """
294+
if argv is None:
295+
argv = sys.argv
296+
295297
parser = argparse.ArgumentParser(
296298
prog="cve-bin-tool",
297299
description="The CVE Binary Tool scans for a number of common, vulnerable open source components (openssl, libpng, libxml2, expat and a few others) to let you know if a given directory or binary file includes common libraries with known vulnerabilities.",

cve_bin_tool/csv2cve.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
ERR_MISSINGCOLUMN = -2
1313

1414

15-
def main(argv=sys.argv, outfile=sys.stdout):
15+
def main(argv=None, outfile=None):
1616
""" Take a list of package information + versions from a CSV file,
1717
and output a list of matching CVES """
1818

19+
if argv is None:
20+
argv = sys.argv
21+
22+
if outfile is None:
23+
outfile = sys.stdout
24+
1925
parser = argparse.ArgumentParser(
2026
prog="csv2cve",
2127
description="This tool takes a list of software + versions from a CSV file and outputs a list of CVEs known to affect those versions",

0 commit comments

Comments
 (0)