From 979ed1cce24fa0cffd4fe414b8a56e17ec032b14 Mon Sep 17 00:00:00 2001 From: Marri Devender Rao Date: Fri, 17 Nov 2017 05:06:25 -0600 Subject: Perform sanity check while restoring error entries Check if the data in the persisted files is valid before restoring the error entries Resolves openbmc/openbmc#2646 Change-Id: Iff0846a3366a27e59484113b7020f540087aa994 Signed-off-by: Marri Devender Rao --- log_manager.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/log_manager.cpp b/log_manager.cpp index fbf6682..0d8e753 100644 --- a/log_manager.cpp +++ b/log_manager.cpp @@ -249,6 +249,10 @@ void Manager::erase(uint32_t entryId) void Manager::restore() { + auto sanity = [](const auto& id, const auto& restoredId) + { + return id == restoredId; + }; std::vector errorIds; fs::path dir(ERRLOG_PERSIST_PATH); @@ -268,13 +272,26 @@ void Manager::restore() *this); if (deserialize(file.path(), *e)) { - e->emit_object_added(); - if (e->severity() >= Entry::sevLowerLimit) + //validate the restored error entry id + if (sanity(static_cast(idNum), e->id())) + { + e->emit_object_added(); + if (e->severity() >= Entry::sevLowerLimit) + { + infoErrors.push_back(idNum); + } + + entries.insert(std::make_pair(idNum, std::move(e))); + errorIds.push_back(idNum); + } + else { - infoErrors.push_back(idNum); + logging::log( + "Failed in sanity check while restoring error entry. " + "Ignoring error entry", + logging::entry("ID_NUM=%d", idNum), + logging::entry("ENTRY_ID=%d", e->id())); } - entries.insert(std::make_pair(idNum, std::move(e))); - errorIds.push_back(idNum); } } -- cgit v1.2.1