summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason M. Bills <jason.m.bills@linux.intel.com>2019-06-18 13:49:54 -0700
committerEd Tanous <ed.tanous@intel.com>2019-06-26 22:46:39 +0000
commit15a86ff65a0ff588adabbeaac7c0e2fe51932357 (patch)
tree799aa9c15272565ee60ed0cca69a399724b0758c
parentb49ac87376278d6085c1d10815672c321a484f35 (diff)
downloadbmcweb-15a86ff65a0ff588adabbeaac7c0e2fe51932357.tar.gz
bmcweb-15a86ff65a0ff588adabbeaac7c0e2fe51932357.zip
Fix parsing of Redfish messages with empty MessageArgs
The current parsing shows an empty string as a MessageArg for messages that have no arguments. This fixes it to correctly display an empty MessageArgs. It also fixes a parsing range check error for the case when a message without MessageArgs is not terminated with a comma. Tested: Verified that messages show without args show in Redfish with an empty MessageArgs. Injected a message without a terminating comma and confirmed that it is correctly parsed and displayed. Change-Id: I896554941d2d239afa889d41edef1f1f71b59906 Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
-rw-r--r--redfish-core/lib/log_services.hpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index f65f3cc..9e3b2f0 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -584,8 +584,6 @@ static int fillEventLogEntryJson(const std::string &logEntryID,
return 1;
}
std::string &messageID = logEntryFields[0];
- std::string &messageArgsStart = logEntryFields[1];
- std::size_t messageArgsSize = logEntryFields.size() - 1;
// Get the Message from the MessageRegistry
const message_registries::Message *message =
@@ -599,18 +597,30 @@ static int fillEventLogEntryJson(const std::string &logEntryID,
severity = message->severity;
}
- // Get the MessageArgs from the log
- boost::beast::span messageArgs(&messageArgsStart, messageArgsSize);
-
- // Fill the MessageArgs into the Message
- int i = 0;
- for (const std::string &messageArg : messageArgs)
+ // Get the MessageArgs from the log if there are any
+ boost::beast::span<std::string> messageArgs;
+ if (logEntryFields.size() > 1)
{
- std::string argStr = "%" + std::to_string(++i);
- size_t argPos = msg.find(argStr);
- if (argPos != std::string::npos)
+ std::string &messageArgsStart = logEntryFields[1];
+ // If the first string is empty, assume there are no MessageArgs
+ std::size_t messageArgsSize = 0;
+ if (!messageArgsStart.empty())
{
- msg.replace(argPos, argStr.length(), messageArg);
+ messageArgsSize = logEntryFields.size() - 1;
+ }
+
+ messageArgs = boost::beast::span(&messageArgsStart, messageArgsSize);
+
+ // Fill the MessageArgs into the Message
+ int i = 0;
+ for (const std::string &messageArg : messageArgs)
+ {
+ std::string argStr = "%" + std::to_string(++i);
+ size_t argPos = msg.find(argStr);
+ if (argPos != std::string::npos)
+ {
+ msg.replace(argPos, argStr.length(), messageArg);
+ }
}
}
OpenPOWER on IntegriCloud