summaryrefslogtreecommitdiff
path: root/include/openbmc_dbus_rest.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/openbmc_dbus_rest.hpp')
-rw-r--r--include/openbmc_dbus_rest.hpp71
1 files changed, 68 insertions, 3 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 5b9b7382d2..7839e65b99 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -577,6 +577,11 @@ int convertJsonToDbus(sd_bus_message *m, const std::string &arg_type,
{
return -1;
}
+ if ((*intValue < std::numeric_limits<int32_t>::lowest()) ||
+ (*intValue > std::numeric_limits<int32_t>::max()))
+ {
+ return -ERANGE;
+ }
int32_t i = static_cast<int32_t>(*intValue);
r = sd_bus_message_append_basic(m, argCode[0], &i);
if (r < 0)
@@ -590,7 +595,18 @@ int convertJsonToDbus(sd_bus_message *m, const std::string &arg_type,
int boolInt = false;
if (intValue != nullptr)
{
- boolInt = *intValue > 0 ? 1 : 0;
+ if (*intValue == 1)
+ {
+ boolInt = true;
+ }
+ else if (*intValue == 0)
+ {
+ boolInt = false;
+ }
+ else
+ {
+ return -ERANGE;
+ }
}
else if (b != nullptr)
{
@@ -616,6 +632,11 @@ int convertJsonToDbus(sd_bus_message *m, const std::string &arg_type,
{
return -1;
}
+ if ((*intValue < std::numeric_limits<int16_t>::lowest()) ||
+ (*intValue > std::numeric_limits<int16_t>::max()))
+ {
+ return -ERANGE;
+ }
int16_t n = static_cast<int16_t>(*intValue);
r = sd_bus_message_append_basic(m, argCode[0], &n);
if (r < 0)
@@ -629,6 +650,11 @@ int convertJsonToDbus(sd_bus_message *m, const std::string &arg_type,
{
return -1;
}
+ if ((*intValue < std::numeric_limits<int64_t>::lowest()) ||
+ (*intValue > std::numeric_limits<int64_t>::max()))
+ {
+ return -ERANGE;
+ }
r = sd_bus_message_append_basic(m, argCode[0], intValue);
if (r < 0)
{
@@ -641,6 +667,11 @@ int convertJsonToDbus(sd_bus_message *m, const std::string &arg_type,
{
return -1;
}
+ if ((*uintValue < std::numeric_limits<uint8_t>::lowest()) ||
+ (*uintValue > std::numeric_limits<uint8_t>::max()))
+ {
+ return -ERANGE;
+ }
uint8_t y = static_cast<uint8_t>(*uintValue);
r = sd_bus_message_append_basic(m, argCode[0], &y);
}
@@ -650,6 +681,11 @@ int convertJsonToDbus(sd_bus_message *m, const std::string &arg_type,
{
return -1;
}
+ if ((*uintValue < std::numeric_limits<uint16_t>::lowest()) ||
+ (*uintValue > std::numeric_limits<uint16_t>::max()))
+ {
+ return -ERANGE;
+ }
uint16_t q = static_cast<uint16_t>(*uintValue);
r = sd_bus_message_append_basic(m, argCode[0], &q);
}
@@ -659,6 +695,11 @@ int convertJsonToDbus(sd_bus_message *m, const std::string &arg_type,
{
return -1;
}
+ if ((*uintValue < std::numeric_limits<uint32_t>::lowest()) ||
+ (*uintValue > std::numeric_limits<uint32_t>::max()))
+ {
+ return -ERANGE;
+ }
uint32_t u = static_cast<uint32_t>(*uintValue);
r = sd_bus_message_append_basic(m, argCode[0], &u);
}
@@ -668,10 +709,24 @@ int convertJsonToDbus(sd_bus_message *m, const std::string &arg_type,
{
return -1;
}
+ if ((*uintValue < std::numeric_limits<uint64_t>::lowest()) ||
+ (*uintValue > std::numeric_limits<uint64_t>::max()))
+ {
+ return -ERANGE;
+ }
r = sd_bus_message_append_basic(m, argCode[0], uintValue);
}
else if (argCode == "d")
{
+ if (doubleValue == nullptr)
+ {
+ return -1;
+ }
+ if ((*doubleValue < std::numeric_limits<double>::lowest()) ||
+ (*doubleValue > std::numeric_limits<double>::max()))
+ {
+ return -ERANGE;
+ }
sd_bus_message_append_basic(m, argCode[0], doubleValue);
}
else if (boost::starts_with(argCode, "a"))
@@ -1857,8 +1912,18 @@ void handlePut(const crow::Request &req, crow::Response &res,
transaction->propertyValue);
if (r < 0)
{
- transaction->setErrorStatus(
- "Invalid arg type");
+ if (r == -ERANGE)
+ {
+ transaction->setErrorStatus(
+ "Provided property value "
+ "is out of range for the "
+ "property type");
+ }
+ else
+ {
+ transaction->setErrorStatus(
+ "Invalid arg type");
+ }
return;
}
r = sd_bus_message_close_container(