diff options
author | Ed Tanous <edtanous@google.com> | 2023-05-31 20:27:49 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-06-01 00:24:16 +0300 |
commit | e14742ca29564138dc03f036591b1af82893bd6b (patch) | |
tree | 237514dec52edd4b6adaea4ef5249a884d58a761 /redfish-core/lib/pcie.hpp | |
parent | aec0ec30d74ade5c791ec792ff9568bb8c1d8a3a (diff) | |
download | bmcweb-e14742ca29564138dc03f036591b1af82893bd6b.tar.xz |
Replace atoi
Atoi has the potential to cause crashes if users request non-integer
pcie function numbers. Replace with functional code.
Tested: WIP
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I6742ff6b69e6df4a4afae26610effa01f2450b1b
Diffstat (limited to 'redfish-core/lib/pcie.hpp')
-rw-r--r-- | redfish-core/lib/pcie.hpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp index d0c88f4609..101259c943 100644 --- a/redfish-core/lib/pcie.hpp +++ b/redfish-core/lib/pcie.hpp @@ -543,15 +543,10 @@ inline bool validatePCIeFunctionId( } inline void addPCIeFunctionProperties( - crow::Response& resp, const std::string& pcieFunctionId, + crow::Response& resp, uint64_t pcieFunctionId, const dbus::utility::DBusPropertiesMap& pcieDevProperties) { - std::string functionName = "Function" + pcieFunctionId; - if (!validatePCIeFunctionId(pcieFunctionId, pcieDevProperties)) - { - messages::resourceNotFound(resp, "PCIeFunction", pcieFunctionId); - return; - } + std::string functionName = "Function" + std::to_string(pcieFunctionId); for (const auto& property : pcieDevProperties) { const std::string* strProperty = @@ -603,7 +598,7 @@ inline void addPCIeFunctionProperties( inline void addPCIeFunctionCommonProperties(crow::Response& resp, const std::string& pcieDeviceId, - const std::string& pcieFunctionId) + uint64_t pcieFunctionId) { resp.addHeader( boost::beast::http::field::link, @@ -613,8 +608,8 @@ inline void addPCIeFunctionCommonProperties(crow::Response& resp, "/redfish/v1/Systems/system/PCIeDevices/{}/PCIeFunctions/{}", pcieDeviceId, pcieFunctionId); resp.jsonValue["Name"] = "PCIe Function"; - resp.jsonValue["Id"] = pcieFunctionId; - resp.jsonValue["FunctionId"] = std::stoi(pcieFunctionId); + resp.jsonValue["Id"] = std::to_string(pcieFunctionId); + resp.jsonValue["FunctionId"] = pcieFunctionId; resp.jsonValue["Links"]["PCIeDevice"]["@odata.id"] = boost::urls::format( "/redfish/v1/Systems/system/PCIeDevices/{}", pcieDeviceId); } @@ -623,12 +618,21 @@ inline void handlePCIeFunctionGet(App& app, const crow::Request& req, const std::shared_ptr<bmcweb::AsyncResp>& aResp, const std::string& pcieDeviceId, - const std::string& pcieFunctionId) + const std::string& pcieFunctionIdStr) { if (!redfish::setUpRedfishRoute(app, req, aResp)) { return; } + uint64_t pcieFunctionId = 0; + std::from_chars_result result = std::from_chars( + &*pcieFunctionIdStr.begin(), &*pcieFunctionIdStr.end(), pcieFunctionId); + if (result.ec != std::errc{} || result.ptr != &*pcieFunctionIdStr.end()) + { + messages::resourceNotFound(aResp->res, "PCIeFunction", + pcieFunctionIdStr); + return; + } getValidPCIeDevicePath( pcieDeviceId, aResp, |