Skip to content

Commit

Permalink
if pciids file not found, deal with the error
Browse files Browse the repository at this point in the history
  • Loading branch information
iadgovuser58 committed Sep 4, 2024
1 parent c29730d commit 0f8fc63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions HIRS_Utils/src/main/java/hirs/utils/PciIds.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Log4j2
public final class PciIds {

private static boolean pciIdsFileNotFound = true;
private static boolean pciIdsFileFound = false;

/**
* This pci ids file can be in different places on different distributions.
Expand Down Expand Up @@ -60,6 +60,7 @@ public final class PciIds {
}
}
if (dbFile != null) {
pciIdsFileFound = true;
InputStream is = null;
try {
is = new FileInputStream(new File(dbFile));
Expand All @@ -78,7 +79,6 @@ public final class PciIds {
}
}
else {
pciIdsFileNotFound = true;
log.info("PCI IDs file was NOT found");
}
}
Expand All @@ -97,7 +97,7 @@ private PciIds() { }
*/
public static ASN1UTF8String translateVendor(final ASN1UTF8String refManufacturer) {
ASN1UTF8String manufacturer = refManufacturer;
if (!pciIdsFileNotFound && manufacturer != null
if (pciIdsFileFound && manufacturer != null
&& manufacturer.getString().trim().matches("^[0-9A-Fa-f]{4}$")) {
Vendor ven = DB.findVendor(manufacturer.getString().toLowerCase());
if (ven != null && !Strings.isNullOrEmpty(ven.getName())) {
Expand All @@ -115,7 +115,7 @@ public static ASN1UTF8String translateVendor(final ASN1UTF8String refManufacture
*/
public static String translateVendor(final String refManufacturer) {
String manufacturer = refManufacturer;
if (!pciIdsFileNotFound && manufacturer != null
if (pciIdsFileFound && manufacturer != null
&& manufacturer.trim().matches("^[0-9A-Fa-f]{4}$")) {
Vendor ven = DB.findVendor(manufacturer.toLowerCase());
if (ven != null && !Strings.isNullOrEmpty(ven.getName())) {
Expand All @@ -137,7 +137,7 @@ public static ASN1UTF8String translateDevice(final ASN1UTF8String refManufacture
final ASN1UTF8String refModel) {
ASN1UTF8String manufacturer = refManufacturer;
ASN1UTF8String model = refModel;
if (!pciIdsFileNotFound
if (pciIdsFileFound
&& manufacturer != null
&& model != null
&& manufacturer.getString().trim().matches("^[0-9A-Fa-f]{4}$")
Expand All @@ -162,7 +162,7 @@ public static ASN1UTF8String translateDevice(final ASN1UTF8String refManufacture
public static String translateDevice(final String refManufacturer,
final String refModel) {
String model = refModel;
if (!pciIdsFileNotFound
if (pciIdsFileFound
&& refManufacturer != null
&& model != null
&& refManufacturer.trim().matches("^[0-9A-Fa-f]{4}$")
Expand Down Expand Up @@ -193,7 +193,7 @@ public static List<String> translateDeviceClass(final String refClassCode) {
List<String> translatedClassCode = new ArrayList<>();

String classCode = refClassCode;
if (!pciIdsFileNotFound && classCode != null
if (pciIdsFileFound && classCode != null
&& classCode.trim().matches("^[0-9A-Fa-f]{6}$")) {
String deviceClass = classCode.substring(0, 2).toLowerCase();
String deviceSubclass = classCode.substring(2, 4).toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public String toString() {
dSEDpciContextInfo += " Subclass = " + classCodeList.get(1) + "\n";
dSEDpciContextInfo += " Programming Interface = " + classCodeList.get(2) + "\n";
} else {
dSEDpciContextInfo += " ** Class code could not be determined **";
dSEDpciContextInfo += " ** Class code could not be determined **\n";
}
dSEDpciContextInfo += " SubsystemVendor = " + translateVendor(subsystemVendorId) + "\n";
dSEDpciContextInfo += " Subsystem = " + translateDevice(subsystemVendorId, subsystemId) + "\n";
Expand Down

0 comments on commit 0f8fc63

Please sign in to comment.