Skip to content

Commit 43f2358

Browse files
fix(parser): drop the Conan user/channel from conan.lock versions (#6139)
* fix(parser): drop the Conan user/channel from conan.lock versions A Conan reference is name/version@user/channel#revision%timestamp, and the @user/channel part is common for packages from private remotes. The conan.lock parser only cut the reference at "#", so the version of "zlib/1.2.12@mycompany/stable#..." was read as "1.2.12@mycompany". That version never matches an exact version in the CVE database and compares as greater than 1.2.12, so CVEs that affect up to 1.2.12 (such as CVE-2022-37434) were missed. Cut each reference at the revision and the user/channel once, then split it into product and version. The requires and build_requires loops now do the same, as suggested in review. Signed-off-by: Darshanpawar7 <170450039+Darshanpawar7@users.noreply.github.com>
1 parent bc5979f commit 43f2358

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎cve_bin_tool/parsers/ccpp.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ def run_checker(self, filename):
4747
data = json.load(fh)
4848
requires = data.get("requires")
4949
build_requires = data.get("build_requires")
50+
# References are name/version, optionally followed by
51+
# @user/channel and then #revision%timestamp
5052
if requires:
5153
for require in requires:
52-
product = require.split("#")[0].split("/")[0]
53-
version = require.split("#")[0].split("/")[1]
54+
reference = require.split("#", 1)[0].split("@", 1)[0]
55+
product, version = reference.split("/", 1)
5456
purl = self.generate_purl(product)
5557
if not self.cve_db:
5658
yield from [
@@ -65,8 +67,8 @@ def run_checker(self, filename):
6567
yield from vendor
6668
if build_requires:
6769
for build_require in build_requires:
68-
product = build_require.split("#")[0].split("/")[0]
69-
version = build_require.split("#")[0].split("/")[1]
70+
reference = build_require.split("#", 1)[0].split("@", 1)[0]
71+
product, version = reference.split("/", 1)
7072
purl = self.generate_purl(product)
7173
if not self.cve_db:
7274
yield from [

‎test/test_parsers.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ def test_conan_lock_without_requires(self):
110110
results = list(CCppParser(None, logger).run_checker(str(file_path)))
111111
self.assertListEqual(results, [])
112112

113+
def test_conan_lock_user_channel_not_in_version(self):
114+
file_path = pathlib.Path(tmpdir, "conan.lock")
115+
file_path.write_text(
116+
'{"version": "0.5", "requires": ['
117+
'"openssl/3.0.8@mycompany/stable#a8f0792d7c5121b954578a7149d23e03%1717541485.78",'
118+
'"zlib/1.2.13#fca992a7d96a1b92bd956caa8a97d18f%1705999194.642"],'
119+
'"build_requires": ["cmake/3.27.7@tools/testing#f305019023c2db74d1001c5afa5cf362"]}'
120+
)
121+
results = CCppParser(None, logger).run_checker(str(file_path))
122+
self.assertListEqual(
123+
[(r.product_info.product, r.product_info.version) for r in results],
124+
[("openssl", "3.0.8"), ("zlib", "1.2.13"), ("cmake", "3.27.7")],
125+
)
126+
113127
def test_ruby_parser_gem_versions(self):
114128
file_path = pathlib.Path(tmpdir, "Gemfile.lock")
115129
file_path.write_text(

0 commit comments

Comments
 (0)