Skip to content

Commit

Permalink
oem-ibm: Handle the json parse exception correctly
Browse files Browse the repository at this point in the history
This commit handles the CoD license json parsing exception by
correctly catching it and returns the error to the caller. Also
made the change to avoid the removal of license json file whenever
shared by the host.

Tested:
Done the sanity testing to verify that json file was kept without
removal.

Signed-off-by: Jayashankar Padath <[email protected]>
  • Loading branch information
jaypadath committed Oct 10, 2024
1 parent b4100da commit dd2c4fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions oem/ibm/libpldmresponder/file_io_type_lic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ int LicenseHandler::updateBinFileAndLicObjs(const fs::path& newLicJsonFilePath)
int rc = PLDM_SUCCESS;
fs::path newLicFilePath(fs::path(licFilePath) / newLicenseFile);
std::ifstream jsonFileNew(newLicJsonFilePath);
Json dataNew;

auto dataNew = Json::parse(jsonFileNew, nullptr, false);
if (dataNew.is_discarded())
try
{
dataNew = Json::parse(jsonFileNew);
}
catch (const Json::parse_error& e)
{
error("Failed to parse the new license json file '{NEW_LIC_JSON}'",
"NEW_LIC_JSON", newLicJsonFilePath);
throw InternalFailure();
return PLDM_ERROR;
}

// Store the json data in a file with binary format
Expand Down
4 changes: 2 additions & 2 deletions oem/ibm/libpldmresponder/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,12 @@ int createOrUpdateLicenseObjs()

if (fs::exists(newLicFilePath))
{
fs::remove_all(newLicFilePath);
// fs::remove_all(newLicFilePath);
}

if (fs::exists(newLicJsonFilePath))
{
fs::remove_all(newLicJsonFilePath);
// fs::remove_all(newLicJsonFilePath);
}
}

Expand Down

0 comments on commit dd2c4fb

Please sign in to comment.