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>
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 @@
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();