Add data validation for PATCH to /Bios/Settings.
New data was validated only using option length.
Added code to check if new value is part of available options.
Error is thrown if the new values is not a valid option.
Tested:
By giving PATCH Request to
'redfish/v1/systems/system/bios/settings'.
Output sample showing success case:
PATCH command raw data:
{
"data":[
{
"AttributeName": "AmpPrefetchEnable",
"AttributeType": "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.String",
"AttributeValue": "0x01"
}
]
}
Response:
{
"@odata.id": "/redfish/v1/Systems/system/Bios/Settings",
"@odata.type": "#Bios.v1_1_0.Bios",
"AttributeRegistry": "BiosAttributeRegistry",
"Id": "BiosSettingsV1",
"Message": "Successfully Completed Request",
"Name": "Bios Settings Version 1"
}
Output sample showing failure case:
PATCH command raw data:
{
"data":[
{
"AttributeName": "AmpPrefetchEnable",
"AttributeType": "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.String",
"AttributeValue": "0x05"
}
]
}
Response:
{
"@odata.id": "/redfish/v1/Systems/system/Bios/Settings",
"@odata.type": "#Bios.v1_1_0.Bios",
"AttributeRegistry": "BiosAttributeRegistry",
"Id": "BiosSettingsV1",
"Name": "Bios Settings Version 1",
"error": {
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The request failed due to an internal service error. The service is still operational.",
"MessageArgs": [],
"MessageId": "Base.1.8.1.InternalError",
"MessageSeverity": "Critical",
"Resolution": "Resubmit the request. If the problem persists, consider resetting the service."
}
],
"code": "Base.1.8.1.InternalError",
"message": "The request failed due to an internal service error. The service is still operational."
}
}
Note: Valid options for knob AmpPrefetchEnable is 0x01 and 0x00 as shown below.
{
"AttributeName": "AmpPrefetchEnable",
"CurrentValue": "0x00",
"DefaultValue": "0x00",
"DisplayName": "AmpPrefetchEnable",
"HelpText": "Set to enable or disable MLC AMP prefetch (MSR 1A4h [4]).",
"MenuPath": "./",
"ReadOnly": false,
"Type": "String",
"Value": [
{
"OneOf": "0x01"
},
{
"OneOf": "0x00"
}
]
}
Signed-off-by: Arun Lal K M <arun.lal@intel.com>
Change-Id: Id66bacf2491d90aa189a8fb0f48d45243195e38c
diff --git a/src/manager.cpp b/src/manager.cpp
index 42a3721..14654be 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -183,29 +183,23 @@
std::get<std::string>(std::get<1>(pair.second));
const auto& options =
std::get<static_cast<uint8_t>(Index::options)>(iter->second);
- int64_t minStringLength = 0;
- int64_t maxStringLength = 0;
- for (const auto& stringOptions : options)
+ auto optionsIterator = options.begin();
+
+ for (; optionsIterator != options.end(); ++optionsIterator)
{
- if (BoundType::MinStringLength == std::get<0>(stringOptions))
+ if (std::get<1>(std::get<1>(*optionsIterator)) == attrValue)
{
- minStringLength =
- std::get<int64_t>(std::get<1>(stringOptions));
- }
- else if (BoundType::MaxStringLength ==
- std::get<0>(stringOptions))
- {
- maxStringLength =
- std::get<int64_t>(std::get<1>(stringOptions));
+ break;
}
}
- if ((attrValue.length() < static_cast<size_t>(minStringLength)) ||
- (attrValue.length() > static_cast<size_t>(maxStringLength)))
+ if (optionsIterator == options.end())
{
+ std::string error =
+ attrValue + " is not a valid value for " + pair.first;
phosphor::logging::log<phosphor::logging::level::ERR>(
- "std::string, length is invalid");
+ error.c_str());
throw InvalidArgument();
}
}