Skip to content

Commit c61aaad

Browse files
committed
hosts: Unset HOSTS_PATH from the environment
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.
1 parent e2d4733 commit c61aaad

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/hosts/hosts.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package hosts
22

33
import (
44
"fmt"
5+
"os"
56
"regexp"
67
"runtime"
78
"sort"
@@ -27,6 +28,14 @@ type Hosts struct {
2728
HostFilter func(string) bool
2829
}
2930

31+
func init() {
32+
// goodhosts unconditionnally uses this environment variable
33+
// as an override for the hosts file to use. We don't want admin-helper
34+
// to modify arbitrary file, so we have to unset it before calling into
35+
// goodhosts.
36+
os.Unsetenv("HOSTS_PATH")
37+
}
38+
3039
func New() (*Hosts, error) {
3140
file, err := hostsfile.NewHosts()
3241
if err != nil {

0 commit comments

Comments
 (0)