oemcommands: check for non-printable characters in biosID
Issue: sdbusplus throws exception and core dumped when non ascii
characters are present in biosID.
Fix: check for non printable characters in biosID string and return
Invalid data field in request response.
Tested:
Command: ipmitool raw 0x30 0x26 0x1 0xAF
Response: Unable to send RAW command (channel=0x0 netfn=0x30 lun=0x0
cmd=0x26 rsp=0xcc): Invalid data field in request
Command: ipmitool raw 0x30 0x26 0x1 0x09
Response: Unable to send RAW command (channel=0x0 netfn=0x30 lun=0x0
cmd=0x26 rsp=0xcc): Invalid data field in request
Command: ipmitool raw 0x30 0x26 0x1 0x1F
Response: Unable to send RAW command (channel=0x0 netfn=0x30 lun=0x0
cmd=0x26 rsp=0xcc): Invalid data field in request
Command: ipmitool raw 0x30 0x26 0x1 0x20
Response: 01
Command: ipmitool raw 0x30 0x26 0x1 0x43
Response: 01
Signed-off-by: Chalapathi Venkataramashetty <chalapathix.venkataramashetty@intel.com>
Change-Id: I7c6733a9f65f740b26a5b92e8b1630b9e52e9622
diff --git a/src/oemcommands.cpp b/src/oemcommands.cpp
index 3ca7caa..46566a3 100644
--- a/src/oemcommands.cpp
+++ b/src/oemcommands.cpp
@@ -290,6 +290,15 @@
return IPMI_CC_REQ_DATA_LEN_INVALID;
}
std::string idString((char*)data->biosId, data->biosIDLength);
+ for (auto idChar : idString)
+ {
+ if (!std::isprint(static_cast<unsigned char>(idChar)))
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "BIOS ID contains non printable character");
+ return IPMI_CC_INVALID_FIELD_REQUEST;
+ }
+ }
std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
std::string service = getService(*dbus, biosVersionIntf, biosActiveObjPath);