Handle out-of-bound exception for toHex API
toHex API throws out-of-bound error if provided input length/size is
greater than 15.
This commit adds code to handle the above error case.
Change-Id: Icd4eb2e3655389e194f621fff9d6df251b851c0a
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp
index 4a821d2..fa8c3fc 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -193,13 +193,46 @@
{
l_result.clear();
size_t l_firstByte = i_keyword[0];
- l_result += commonUtility::toHex(l_firstByte >> 4);
- l_result += commonUtility::toHex(l_firstByte & 0x0f);
+
+ auto l_hexValue = commonUtility::toHex(l_firstByte >> 4);
+
+ if (!l_hexValue)
+ {
+ throw std::runtime_error("Out of bound error");
+ }
+
+ l_result += l_hexValue;
+
+ l_hexValue = commonUtility::toHex(l_firstByte & 0x0f);
+
+ if (!l_hexValue)
+ {
+ throw std::runtime_error("Out of bound error");
+ }
+
+ l_result += l_hexValue;
+
for (size_t i = 1; i < i_keyword.size(); ++i)
{
l_result += ":";
- l_result += commonUtility::toHex(i_keyword[i] >> 4);
- l_result += commonUtility::toHex(i_keyword[i] & 0x0f);
+
+ l_hexValue = commonUtility::toHex(i_keyword[i] >> 4);
+
+ if (!l_hexValue)
+ {
+ throw std::runtime_error("Out of bound error");
+ }
+
+ l_result += l_hexValue;
+
+ l_hexValue = commonUtility::toHex(i_keyword[i] & 0x0f);
+
+ if (!l_hexValue)
+ {
+ throw std::runtime_error("Out of bound error");
+ }
+
+ l_result += l_hexValue;
}
}
else if (i_encoding == "DATE")