summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2019-02-15 10:35:50 -0600
committerMatthew Barth <msbarth@us.ibm.com>2019-02-18 09:46:13 -0600
commit221c90c39a5cbd4ed71211b47af80f967c4575c3 (patch)
tree9a72cebb02a82f89ccabe0ab9785d2fd56bb6e22
parenta2bed6ed873b18cd150d3e26845391df03649a78 (diff)
downloadphosphor-fan-presence-221c90c39a5cbd4ed71211b47af80f967c4575c3.zip
phosphor-fan-presence-221c90c39a5cbd4ed71211b47af80f967c4575c3.tar.gz
Verify mode provided is supported
Before updating the current mode, verify that the mode provided by the end-user is in the list of modes that are supported. Tested: Only supported modes can be set as the current mode Change-Id: Ie21839b6bf7245756fedf417e143c28bc9da32f1 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
-rw-r--r--control/zone.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/control/zone.cpp b/control/zone.cpp
index 0278de8..6efbe73 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -643,7 +643,17 @@ std::string Zone::current(std::string value)
auto current = ThermalObject::current();
std::transform(value.begin(), value.end(), value.begin(), toupper);
- if (value != current)
+ auto supported = ThermalObject::supported();
+ auto isSupported = std::any_of(
+ supported.begin(),
+ supported.end(),
+ [&value](auto& s)
+ {
+ std::transform(s.begin(), s.end(), s.begin(), toupper);
+ return value == s;
+ });
+
+ if (value != current && isSupported)
{
current = ThermalObject::current(value);
saveCurrentMode();
OpenPOWER on IntegriCloud