4
4
from __future__ import annotations
5
5
6
6
import re
7
+ import sys
7
8
from collections import defaultdict
8
9
from logging import Logger
9
10
from pathlib import Path
15
16
from cve_bin_tool .cvedb import CVEDB
16
17
from cve_bin_tool .input_engine import TriageData
17
18
from cve_bin_tool .log import LOGGER
18
- from cve_bin_tool .util import ProductInfo , Remarks
19
+ from cve_bin_tool .util import (
20
+ ProductInfo ,
21
+ Remarks ,
22
+ find_product_location ,
23
+ validate_location ,
24
+ )
19
25
from cve_bin_tool .validator import validate_cyclonedx , validate_spdx
20
26
21
27
from .swid_parser import SWIDParser
@@ -80,10 +86,17 @@ def common_prefix_split(self, product, version) -> list[ProductInfo]:
80
86
len (common_prefix_vendor ) == 1
81
87
and common_prefix_vendor [0 ] != "UNKNOWN"
82
88
):
89
+ location = find_product_location (common_prefix_product )
90
+ if location is None :
91
+ location = "NotFound"
92
+ if validate_location (location ) is False :
93
+ raise ValueError (f"Invalid location { location } for { product } " )
83
94
found_common_prefix = True
84
95
for vendor in common_prefix_vendor :
85
96
parsed_data .append (
86
- ProductInfo (vendor , common_prefix_product , version )
97
+ ProductInfo (
98
+ vendor , common_prefix_product , version , location
99
+ )
87
100
)
88
101
break
89
102
if not found_common_prefix :
@@ -97,8 +110,15 @@ def common_prefix_split(self, product, version) -> list[ProductInfo]:
97
110
temp = self .get_vendor (sp )
98
111
if len (temp ) > 1 or (len (temp ) == 1 and temp [0 ] != "UNKNOWN" ):
99
112
for vendor in temp :
113
+ location = find_product_location (sp )
114
+ if location is None :
115
+ location = "NotFound"
116
+ if validate_location (location ) is False :
117
+ raise ValueError (
118
+ f"Invalid location { location } for { product } "
119
+ )
100
120
# if vendor is not None:
101
- parsed_data .append (ProductInfo (vendor , sp , version ))
121
+ parsed_data .append (ProductInfo (vendor , sp , version , location ))
102
122
return parsed_data
103
123
104
124
def scan_file (self ) -> dict [ProductInfo , TriageData ]:
@@ -139,9 +159,21 @@ def scan_file(self) -> dict[ProductInfo, TriageData]:
139
159
vendor_set = self .get_vendor (product )
140
160
for vendor in vendor_set :
141
161
# if vendor is not None:
142
- parsed_data .append (ProductInfo (vendor , product , version ))
162
+ location = find_product_location (product )
163
+ if location is None :
164
+ location = "NotFound"
165
+ if validate_location (location ) is False :
166
+ raise ValueError (f"Invalid location { location } for { product } " )
167
+ parsed_data .append (ProductInfo (vendor , product , version , location ))
143
168
else :
144
- parsed_data .append (ProductInfo (module_vendor , product , version ))
169
+ location = find_product_location (product )
170
+ if location is None :
171
+ location = "NotFound"
172
+ if validate_location (location ) is False :
173
+ raise ValueError (f"Invalid location { location } for { product } " )
174
+ parsed_data .append (
175
+ ProductInfo (module_vendor , product , version , location )
176
+ )
145
177
146
178
for row in parsed_data :
147
179
self .sbom_data [row ]["default" ] = {
@@ -357,7 +389,6 @@ def decode_purl(self, purl) -> (str | None, str | None, str | None):
357
389
358
390
359
391
if __name__ == "__main__" :
360
- import sys
361
392
362
393
file = sys .argv [1 ]
363
394
sbom = SBOMManager (file )
0 commit comments