summaryrefslogtreecommitdiff
path: root/redfish-core/lib/hypervisor_system.hpp
diff options
context:
space:
mode:
authorRavi Teja <raviteja28031990@gmail.com>2021-01-07 14:13:14 +0300
committerEd Tanous <ed@tanous.net>2021-03-22 20:09:58 +0300
commit64face749ab8eabcc7c9007d8b6c1e2863f7bbe2 (patch)
tree342541437ce14b87e7bdf2b13dd0aff85d5b9117 /redfish-core/lib/hypervisor_system.hpp
parentc951448acb5c81a69569326c080b1a50e5678cbf (diff)
downloadbmcweb-64face749ab8eabcc7c9007d8b6c1e2863f7bbe2.tar.xz
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
Diffstat (limited to 'redfish-core/lib/hypervisor_system.hpp')
-rw-r--r--redfish-core/lib/hypervisor_system.hpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index 3367a14612..e320e360df 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -929,7 +929,7 @@ class HypervisorInterface : public Node
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 @@ class HypervisorInterface : public Node
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