summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Tanous <ed.tanous@intel.com>2018-05-09 17:28:05 -0700
committerEd Tanous <ed.tanous@intel.com>2018-05-09 17:34:47 -0700
commit7aa715b286f18129a2e7f1ebdaa4e35fc0919bd4 (patch)
tree0c1da70f8294c78224cc4431e6eeaea593b563db
parent75710b6a1a78cb81dd4fd2f3271f398a42179599 (diff)
downloadphosphor-time-manager-7aa715b286f18129a2e7f1ebdaa4e35fc0919bd4.tar.gz
phosphor-time-manager-7aa715b286f18129a2e7f1ebdaa4e35fc0919bd4.zip
Follow secure coding standards for interactions with the mapper
This patchset updates phosphor-time-manager to follow secure coding guidelines when interacting with the mapper. Specifically, it replaces uses of std::map with std::vector<std::pair<>>, which should net some small performance wins. This change also causes time-manager to properly enumerate each response. Tested-By: Built with changeset, and verified via d-feet that /xyz/openbmc_project/time/host and /xyz/openbmc_project/time/bmc were present, and verified reading of the "Elapsed" parameter returned the expected time result. Change-Id: If4329d533641595cf0b50c4e50e2dda69b299f52 Signed-off-by: Ed Tanous <ed.tanous@intel.com>
-rw-r--r--settings.cpp31
-rw-r--r--utils.cpp9
2 files changed, 24 insertions, 16 deletions
diff --git a/settings.cpp b/settings.cpp
index a3eada9..704905a 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -35,7 +35,8 @@ Objects::Objects()
}
using Interfaces = std::vector<Interface>;
- using MapperResponse = std::map<Path, std::map<Service, Interfaces>>;
+ using MapperResponse = std::vector<
+ std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>;
MapperResponse result;
response.read(result);
if (result.empty())
@@ -47,19 +48,23 @@ Objects::Objects()
for (const auto& iter : result)
{
const Path& path = iter.first;
- const Interface& interface = iter.second.begin()->second.front();
-
- if (timeOwnerIntf == interface)
- {
- timeOwner = path;
- }
- else if (timeSyncIntf == interface)
- {
- timeSyncMethod = path;
- }
- else if (hostStateIntf == interface)
+ for (const auto& service_iter: iter.second)
{
- hostState = path;
+ for (const Interface& interface: service_iter.second)
+ {
+ if (timeOwnerIntf == interface)
+ {
+ timeOwner = path;
+ }
+ else if (timeSyncIntf == interface)
+ {
+ timeSyncMethod = path;
+ }
+ else if (hostStateIntf == interface)
+ {
+ hostState = path;
+ }
+ }
}
}
}
diff --git a/utils.cpp b/utils.cpp
index 25b8f8c..778487f 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -47,7 +47,8 @@ std::string getService(sdbusplus::bus::bus& bus,
MethodError::MISC({}));
}
- std::map<std::string, std::vector<std::string>> mapperResponse;
+ std::vector<std::pair<std::string, std::vector<std::string>>>
+ mapperResponse;
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
@@ -57,8 +58,10 @@ std::string getService(sdbusplus::bus::bus& bus,
MethodError::INTERFACE(interface),
MethodError::MISC("Error reading mapper response"));
}
-
- return mapperResponse.begin()->first;
+ if (mapperResponse.size() < 1){
+ return "";
+ }
+ return mapperResponse[0].first;
}
Mode strToMode(const std::string& mode)
OpenPOWER on IntegriCloud