Skip to content

False assumption: IPs appear in a single position #25

@tomjn

Description

@tomjn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions