22# SPDX-License-Identifier: GPL-3.0-or-later
33
44import os
5+ import re
56import sqlite3
67import sys
78from collections import defaultdict
@@ -72,7 +73,23 @@ def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
7273 """
7374 # Removing * from vendors that are guessed by the package list parser
7475 vendor = product_info .vendor .replace ("*" , "" )
75- self .cursor .execute (query , [vendor , product_info .product , product_info .version ])
76+
77+ # Need to manipulate version to ensure canonical form of version
78+ if product_info .product == "openssl" :
79+ pv = re .search (r"\d[.\d]*[a-z]?" , product_info .version )
80+ parsed_version_between = parse_version (self .openssl_convert (pv .group (0 )))
81+ else :
82+ # Ensure canonical form of version numbering
83+ if ":" in product_info .version :
84+ # Handle x:a.b<string> e.g. 2:7.4+23
85+ components = product_info .version .split (":" )
86+ pv = re .search (r"\d[.\d]*" , components [1 ])
87+ else :
88+ # Handle a.b.c<string> e.g. 1.20.9rel1
89+ pv = re .search (r"\d[.\d]*" , product_info .version )
90+ parsed_version = parse_version (pv .group (0 ))
91+
92+ self .cursor .execute (query , [vendor , product_info .product , str (parsed_version )])
7693
7794 cve_list = list (map (lambda x : x [0 ], self .cursor .fetchall ()))
7895
@@ -88,8 +105,6 @@ def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
88105 WHERE vendor=? AND product=? AND version=?
89106 """
90107
91- # Removing * from vendors that are guessed by the package list parser
92- vendor = product_info .vendor .replace ("*" , "" )
93108 self .cursor .execute (query , [vendor , product_info .product , "*" ])
94109
95110 for cve_range in self .cursor :
@@ -101,8 +116,6 @@ def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
101116 version_end_excluding ,
102117 ) = cve_range
103118
104- parsed_version = parse_version (product_info .version )
105-
106119 # pep-440 doesn't include versions of the type 1.1.0g used by openssl
107120 # so if this is openssl, convert the last letter to a .number
108121 if product_info .product == "openssl" :
@@ -112,9 +125,7 @@ def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
112125 version_start_excluding = self .openssl_convert (version_start_excluding )
113126 version_end_including = self .openssl_convert (version_end_including )
114127 version_end_excluding = self .openssl_convert (version_end_excluding )
115- parsed_version = parse_version (
116- self .openssl_convert (product_info .version )
117- )
128+ parsed_version = parsed_version_between
118129
119130 # check the start range
120131 passes_start = False
0 commit comments