diff options
author | Michael Tritz <mtritz@us.ibm.com> | 2017-08-04 14:00:29 -0500 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-18 17:28:05 +0000 |
commit | 36417922b17a15595d4fae446c3bf53c16e28ced (patch) | |
tree | 929a90dba4036d8b1bd79f334ad02871612af5c0 /serialize.cpp | |
parent | b8e7f3136f8371837c329d952333e6389601af69 (diff) | |
download | openpower-pnor-code-mgmt-36417922b17a15595d4fae446c3bf53c16e28ced.tar.gz openpower-pnor-code-mgmt-36417922b17a15595d4fae446c3bf53c16e28ced.zip |
Fix for restoreFromFile cereal exception
This commit provides a fix for an issue in which the cereal
restoreFromFile() would crash the host software updater in the event
that a priority persistence file is empty.
Resolves openbmc/openbmc#2091
Change-Id: Icca5d68ef250e2662cd02075c6ba731e4ab768b0
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
Diffstat (limited to 'serialize.cpp')
-rw-r--r-- | serialize.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/serialize.cpp b/serialize.cpp index 8e957272b..a499798c4 100644 --- a/serialize.cpp +++ b/serialize.cpp @@ -26,15 +26,24 @@ void storeToFile(std::string versionId, uint8_t priority) oarchive(cereal::make_nvp("priority", priority)); } -void restoreFromFile(std::string versionId, uint8_t *priority) +bool restoreFromFile(std::string versionId, uint8_t& priority) { std::string path = PERSIST_DIR + versionId; if (fs::exists(path)) { std::ifstream is(path.c_str(), std::ios::in); - cereal::JSONInputArchive iarchive(is); - iarchive(cereal::make_nvp("priority", *priority)); + try + { + cereal::JSONInputArchive iarchive(is); + iarchive(cereal::make_nvp("priority", priority)); + return true; + } + catch(cereal::RapidJSONException& e) + { + fs::remove(path); + } } + return false; } void removeFile(std::string versionId) |