Fix hypervisor IPv4StaticAddresses property patch
This commit fixes bmcweb crash while patching
"IPv4StaticAddresses" property with below values
'{"IPv4StaticAddresses": null}'
'{"IPv4StaticAddresses": []}'
Tested By:
GET
PATCH
'{"IPv4StaticAddresses": null}' returned a 400
'{"IPv4StaticAddresses": []}' returned a 400
'{"IPv4StaticAddresses": [null]}' returned a 200 and deleted the entry
Signed-off-by: Ravi Teja <raviteja28031990@gmail.com>
Change-Id: Ia310818c87fc1a425d32dd3648c2cbdd6fe5f526
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index 3367a14..e320e36 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -929,7 +929,7 @@
const std::string& ifaceId = params[0];
std::optional<std::string> hostName;
- std::optional<nlohmann::json> ipv4StaticAddresses;
+ std::optional<std::vector<nlohmann::json>> ipv4StaticAddresses;
std::optional<nlohmann::json> ipv4Addresses;
std::optional<nlohmann::json> dhcpv4;
std::optional<bool> ipv4DHCPEnabled;
@@ -973,6 +973,29 @@
if (ipv4StaticAddresses)
{
const nlohmann::json& ipv4Static = *ipv4StaticAddresses;
+ if (ipv4Static.begin() == ipv4Static.end())
+ {
+ messages::propertyValueTypeError(
+ asyncResp->res,
+ ipv4Static.dump(
+ 2, ' ', true,
+ nlohmann::json::error_handler_t::replace),
+ "IPv4StaticAddresses");
+ return;
+ }
+
+ // One and only one hypervisor instance supported
+ if (ipv4Static.size() != 1)
+ {
+ messages::propertyValueFormatError(
+ asyncResp->res,
+ ipv4Static.dump(
+ 2, ' ', true,
+ nlohmann::json::error_handler_t::replace),
+ "IPv4StaticAddresses");
+ return;
+ }
+
const nlohmann::json& ipv4Json = ipv4Static[0];
// Check if the param is 'null'. If its null, it means that
// user wants to delete the IP address. Deleting the IP