Fix for empty string in IPv4 PATCH.
Unfortunately current implementation handles empty string as 0, so format verification is OK,
but IPs like XXX...XXX should not be accepted.
Change-Id: Ibdc526a7118bffdc6a028343a32711d1ad6e2d62
Signed-off-by: Kowalski, Kamil <kamil.kowalski@intel.com>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 6c2bf6c..630ebd1 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -324,9 +324,13 @@
char *endPtr;
long previousValue = 255;
bool firstZeroInByteHit;
- for (uint8_t byteIdx = 0; byteIdx < ipV4AddressSectionsCount; byteIdx++) {
+ for (const std::string &byte : bytesInMask) {
+ if (byte.empty()) {
+ return false;
+ }
+
// Use strtol instead of stroi to avoid exceptions
- long value = std::strtol(bytesInMask[byteIdx].c_str(), &endPtr, 10);
+ long value = std::strtol(byte.c_str(), &endPtr, 10);
// endPtr should point to the end of the string, otherwise given string
// is not 100% number