Skip to content

Commit

Permalink
hosts: Unset HOSTS_PATH from the environment
Browse files Browse the repository at this point in the history
goodhosts unconditionnally uses this environment variable as an override
for the hosts file to use. We don't want admin-helper to modify
arbitrary file, so we have to unset it before calling into goodhosts.
  • Loading branch information
cfergeau committed Nov 26, 2021
1 parent e2d4733 commit c61aaad
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/hosts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hosts

import (
"fmt"
"os"
"regexp"
"runtime"
"sort"
Expand All @@ -27,6 +28,14 @@ type Hosts struct {
HostFilter func(string) bool
}

func init() {
// goodhosts unconditionnally uses this environment variable
// as an override for the hosts file to use. We don't want admin-helper
// to modify arbitrary file, so we have to unset it before calling into
// goodhosts.
os.Unsetenv("HOSTS_PATH")
}

func New() (*Hosts, error) {
file, err := hostsfile.NewHosts()
if err != nil {
Expand Down

0 comments on commit c61aaad

Please sign in to comment.