Fix bmcweb coredump by Non-existent PCIeFunctionId
When a non-existent PCIeFunctionId is queried, bmcweb
returns the success but with the incorrect output.
```
curl -k -X GET https://${bmc}:18080/redfish/v1/Systems/system/PCIeDevices/pcie_card1/PCIeFunctions/12
{
"@odata.id": "/redfish/v1/Systems/system/PCIeDevices/pcie_card1/PCIeFunctions/12",
"@odata.type": "#PCIeFunction.v1_2_3.PCIeFunction",
"FunctionId": 12,
"Id": "12",
"Links": {
"PCIeDevice": {
"@odata.id": "/redfish/v1/Systems/system/PCIeDevices/pcie_card1"
}
},
"Name": "PCIe Function"
}%
```
This should be resulted as
```
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The requested resource of type PCIeFunction named '12' was not found.",
```
Change-Id: If6a1453e3e549e07b6961ff80ebf37b0537e2b7c
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index 101259c..93b15c3 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -524,10 +524,10 @@
}
inline bool validatePCIeFunctionId(
- const std::string& pcieFunctionId,
+ uint64_t pcieFunctionId,
const dbus::utility::DBusPropertiesMap& pcieDevProperties)
{
- std::string functionName = "Function" + pcieFunctionId;
+ std::string functionName = "Function" + std::to_string(pcieFunctionId);
std::string devIDProperty = functionName + "DeviceId";
const std::string* devIdProperty = nullptr;
@@ -642,6 +642,12 @@
aResp, pcieDevicePath, service,
[aResp, pcieDeviceId, pcieFunctionId](
const dbus::utility::DBusPropertiesMap& pcieDevProperties) {
+ if (!validatePCIeFunctionId(pcieFunctionId, pcieDevProperties))
+ {
+ messages::resourceNotFound(aResp->res, "PCIeFunction",
+ std::to_string(pcieFunctionId));
+ return;
+ }
addPCIeFunctionCommonProperties(aResp->res, pcieDeviceId,
pcieFunctionId);
addPCIeFunctionProperties(aResp->res, pcieFunctionId,