Fix JSON lookup for VPD File
This commit fixes an incorrect lookup for the VPD
file path in the VPD JSON. Adds a check to ensure the
file path actually exists in the JSON before attempting
access.
Tested:
Made sure we don't run into JSON lookup exception after the fix.
Signed-off-by: Santosh Puranik <santosh.puranik@in.ibm.com>
Change-Id: Ic3994a6e5cbf5175227e8de8fb0b6bcbc30713c0
diff --git a/ibm_vpd_app.cpp b/ibm_vpd_app.cpp
index 1914b2f..d8f8cd4 100644
--- a/ibm_vpd_app.cpp
+++ b/ibm_vpd_app.cpp
@@ -909,6 +909,8 @@
CLI11_PARSE(app, argc, argv);
+ cout << "Parser launched with file: " << file << "\n";
+
// PEL severity should be ERROR in case of any system VPD failure
if (file == systemVpdFilePath)
{
@@ -940,12 +942,22 @@
throw(VpdJsonException("Json parsing failed", jsonToParse));
}
+ // Do we have the mandatory "frus" section?
+ if (js.find("frus") == js.end())
+ {
+ throw(VpdJsonException("FRUs section not found in JSON",
+ jsonToParse));
+ }
+
// Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@)
if (file.find("/ahb:apb") != string::npos)
{
// Translate udev path to a generic /sys/bus/.. file path.
udevToGenericPath(file);
- if (js["frus"][file].at(0).value("isSystemVpd", false))
+ cout << "Path after translation: " << file << "\n";
+
+ if ((js["frus"].find(file) != js["frus"].end()) &&
+ (js["frus"][file].at(0).value("isSystemVpd", false)))
{
return 0;
}
@@ -956,8 +968,7 @@
cerr << "The EEPROM path <" << file << "> is not valid.";
return 0;
}
- if ((js.find("frus") == js.end()) ||
- (js["frus"].find(file) == js["frus"].end()))
+ if (js["frus"].find(file) == js["frus"].end())
{
cout << "Device path not in JSON, ignoring" << endl;
return 0;