@@ -85,7 +85,7 @@ def find_vendor(self, product, version):
85
85
)
86
86
return vendorlist
87
87
88
- def generate_purl (self , product , vendor , qualifier = {}, subpath = None ):
88
+ def generate_purl (self , product , vendor = "" , qualifier = {}, subpath = None ):
89
89
"""Generate purl string based on various components."""
90
90
purl = PackageURL (
91
91
type = self .purl_pkg_type ,
@@ -104,36 +104,48 @@ def find_vendor_from_purl(self, purl, ver) -> Tuple[List[ScanInfo], bool]:
104
104
It then decodes the CPE data to extract vendor, product, and version information. If the version matches the provided
105
105
version, it constructs a ScanInfo object for each matching entry and returns a list of these objects.
106
106
"""
107
-
108
- query = "SELECT cpe from purl2cpe WHERE purl=?"
109
- cursor = self .db_open_and_get_cursor ()
110
- cursor .execute (query , [str (purl )])
111
- cpeList = cursor .fetchall ()
112
- vendorlist : list [ScanInfo ] = []
113
- vendors = set ()
114
-
115
- if cpeList != []:
116
- for item in cpeList :
117
- vendor , product , version = self .decode_cpe23 (str (item ))
118
- vendors .add ((vendor , product ))
119
- else :
120
- return vendorlist , False
121
- purl_with_ver = f"{ str (purl )} @{ ver } "
122
- for vendor , product in vendors :
123
- vendorlist .append (
124
- ScanInfo (
125
- ProductInfo (
126
- vendor ,
127
- product ,
128
- ver ,
129
- "/usr/local/bin/product" ,
130
- purl = purl_with_ver ,
131
- ),
132
- self .filename ,
107
+ try :
108
+ purl = purl .to_dict ()
109
+ param1 = f"pkg:{ purl ['type' ]} /{ purl ['name' ]} "
110
+ param2 = f"pkg:{ purl ['type' ]} /%/{ purl ['name' ]} "
111
+
112
+ query = """
113
+ SELECT cpe from purl2cpe WHERE purl LIKE ?
114
+ UNION
115
+ SELECT cpe from purl2cpe WHERE purl LIKE ?
116
+ """
117
+ cursor = self .db_open_and_get_cursor ()
118
+ cursor .execute (query , (param1 , param2 ))
119
+ cpeList = cursor .fetchall ()
120
+ vendorlist : list [ScanInfo ] = []
121
+ vendors = set ()
122
+
123
+ if cpeList != []:
124
+ for item in cpeList :
125
+ vendor , _ , _ = self .decode_cpe23 (str (item ))
126
+ vendors .add ((vendor , purl ["name" ]))
127
+ else :
128
+ return vendorlist , False
129
+
130
+ purl_with_ver = f"{ str (purl )} @{ ver } "
131
+ for vendor , product in vendors :
132
+ vendorlist .append (
133
+ ScanInfo (
134
+ ProductInfo (
135
+ vendor ,
136
+ product ,
137
+ ver ,
138
+ "/usr/local/bin/product" ,
139
+ purl_with_ver ,
140
+ ),
141
+ self .filename ,
142
+ )
133
143
)
134
- )
135
144
136
- return vendorlist , True
145
+ return vendorlist , True
146
+ except Exception as e :
147
+ self .logger .error (f"Error occurred: { e } " )
148
+ return [], False
137
149
138
150
def db_open_and_get_cursor (self ) -> sqlite3 .Cursor :
139
151
"""Opens connection to sqlite database, returns cursor object."""
0 commit comments