https://github.com/goodhosts/hostsfile/blob/master/hosts.go#L103
The code that adds a host performs a check to see if a line with the IP is already present, and if so, it inspects the hosts on that line and only adds the host if it is not listed.
However, this assumption is not true.
For example, consider this hosts file:
127.0.0.1 tom.test
127.0.0.1 tom.test example.test
Goodhosts will pick up the first line, see that example.test is not present, and add the host, leading to duplication.
Instead, this needs to be a loop, and position := h.getIpPosition(ip) needs to be positions := h.getIpPositions(ip).
Likewise, if an existing entry is present, this code does not remove it, which can lead to hostnames being defined multiple times but with different IPs
https://github.com/goodhosts/hostsfile/blob/master/hosts.go#L103
The code that adds a host performs a check to see if a line with the IP is already present, and if so, it inspects the hosts on that line and only adds the host if it is not listed.
However, this assumption is not true.
For example, consider this hosts file:
Goodhosts will pick up the first line, see that
example.testis not present, and add the host, leading to duplication.Instead, this needs to be a loop, and
position := h.getIpPosition(ip)needs to bepositions := h.getIpPositions(ip).Likewise, if an existing entry is present, this code does not remove it, which can lead to hostnames being defined multiple times but with different IPs