Defect SW541296:vpd-tool write failure
vpd-tool write option failed to write the given input.
<The iostream::eof flag is set only by all standard input operations
when the End-of-File is reached.>
Here the issue was, the string stream's eof bit got set to true only
after a read beyond the last character in the stream. This made to loop
for (stream_length+1) times, which appends the last character twice in
the vector buffer.
This commit has the fix for it - by looping around the stream only
for the actual length of the stream.
Test:Tested on everest
1.
root@ever27bmc:/tmp# ./vpd-tool -r -O /system/chassis/motherboard/dasd_backplane/panel1 -R VINI -K DR
{
"/system/chassis/motherboard/dasd_backplane/panel1": {
"DR": "CEC OP PANEL LCD"
}
}
root@ever27bmc:/tmp# ./vpd-tool -w -O /system/chassis/motherboard/dasd_backplane/panel1 -R VINI -K DR -V 0x3132
root@ever27bmc:/tmp# ./vpd-tool -r -O /system/chassis/motherboard/dasd_backplane/panel1 -R VINI -K DR
{
"/system/chassis/motherboard/dasd_backplane/panel1": {
"DR": "12C OP PANEL LCD"
}
}
2.
root@ever27bmc:/tmp# ./vpd-tool -w -O /system/chassis/motherboard/dasd_backplane/panel1 -R VINI -K DR -V 0x61yy
Provide a valid hexadecimal input.
3.
root@ever27bmc:/tmp# ./vpd-tool -w -O /system/chassis/motherboard/dasd_backplane/panel1 -R VINI -K DR -V 0x61A
VPD-TOOL write option accepts 2 digit hex numbers. (Eg. 0x1 should be given as 0x01). Aborting the write operation.
Signed-off-by: Priyanga Ramasamy <priyanga24@in.ibm.com>
Change-Id: I86096e7f21ba306094e517e84ce270f40cf51794
diff --git a/vpd_tool_impl.cpp b/vpd_tool_impl.cpp
index 931bba1..8c5a92e 100644
--- a/vpd_tool_impl.cpp
+++ b/vpd_tool_impl.cpp
@@ -30,9 +30,21 @@
ss.str(value.substr(2));
string byteStr{};
- while (!ss.eof())
+ if (value.length() % 2 != 0)
{
- ss >> setw(2) >> byteStr;
+ throw runtime_error(
+ "VPD-TOOL write option accepts 2 digit hex numbers. (Eg. 0x1 "
+ "should be given as 0x01). Aborting the write operation.");
+ }
+
+ if (value.find_first_not_of("0123456789abcdefABCDEF", 2) !=
+ std::string::npos)
+ {
+ throw runtime_error("Provide a valid hexadecimal input.");
+ }
+
+ while (ss >> setw(2) >> byteStr)
+ {
uint8_t byte = strtoul(byteStr.c_str(), nullptr, 16);
val.push_back(byte);