Fix potential increment past end in ethernet
Coverity warns that this is a bug. GCC-15 treats it as a hard error.
Incrementing past the end of an iterator is undefined behavior, so add a
check to ensure it never happens.
This was originally submitted as part of a larger change here:
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/81720
But because this is now breaking the build, put this in its own commit.
Tested: Not great testing available for this, and Redfish array behavior
is very subtle. Inspection only.
Change-Id: I15669bb7212fbd330cf1022670c9ad558ffabe73
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 1031e3d..53e21c5 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -1661,8 +1661,11 @@
lastGatewayPath = pathString;
}
}
- nicIpEntry++;
- nicIpEntry = getNextStaticIpEntry(nicIpEntry, ipv4Data.cend());
+ if (nicIpEntry != ipv4Data.end())
+ {
+ nicIpEntry++;
+ nicIpEntry = getNextStaticIpEntry(nicIpEntry, ipv4Data.cend());
+ }
entryIdx++;
}