phosphor-log-manager: Fix for deserialize cereal exception
This commit provides a fix for an issue in which the cereal
deserialize() would crash the phosphor-log-manager incase
persistence file is empty in restore path.
Resolves openbmc/openbmc#2337
Change-Id: Id9d8c066d0dc50cba62a67060c1ee8d43d046ff1
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
diff --git a/elog_serialize.cpp b/elog_serialize.cpp
index 72dc295..f8c40e1 100644
--- a/elog_serialize.cpp
+++ b/elog_serialize.cpp
@@ -3,7 +3,9 @@
#include <cereal/types/tuple.hpp>
#include <cereal/archives/binary.hpp>
#include <fstream>
+
#include "elog_serialize.hpp"
+#include <phosphor-logging/log.hpp>
namespace phosphor
{
@@ -65,14 +67,23 @@
bool deserialize(const fs::path& path, Entry& e)
{
- if (fs::exists(path))
+ try
{
- std::ifstream is(path.c_str(), std::ios::in | std::ios::binary);
- cereal::BinaryInputArchive iarchive(is);
- iarchive(e);
- return true;
+ if (fs::exists(path))
+ {
+ std::ifstream is(path.c_str(), std::ios::in | std::ios::binary);
+ cereal::BinaryInputArchive iarchive(is);
+ iarchive(e);
+ return true;
+ }
+ return false;
}
- return false;
+ catch(cereal::Exception& e)
+ {
+ log<level::ERR>(e.what());
+ fs::remove(path);
+ return false;
+ }
}
} // namespace logging