As part of https://github.com/cfengine/core/pull/4680 a naive implementation of StringIsLocalhostIP() function was introduced. It was only used as a helper recognition function in the code there so it didn't have to be bullet-proof. Nevertheless, a proper function with unit tests and also recognizing IPv6 localhost addresses would be better.
- a new StringIsLocalhostIP() function added to libntech/libutils
- function properly checks if the given string is a localhost IP address or not
- IPv6 localhost addresses are recognized
- the function has an extensive unit test coverage for both valid and invalid strings
- (optional) the function should only iterate over the string once (keep in mind that things like strlen() also iterate over the string)
- the function is used in cf-execd/cf-execd-runagent.c instead of the naive implementation
- manual checks are performed to see if it can be used somewhere else where we already do localhost IP address recognition/validation