Skip to content

Commit

Permalink
Merge pull request #393 from orange-guo/main
Browse files Browse the repository at this point in the history
enhancement(link_local_dns.go): avoid occur runtime panic when the nameservers are empty.
  • Loading branch information
dmikusa authored May 20, 2024
2 parents 426ffbb + 926d265 commit 62a9f74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions helper/link_local_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ type LinkLocalDNS struct {
}

func (l LinkLocalDNS) Execute() (map[string]string, error) {
// In some cases, the nameservers are empty.
// For example, when using the host network, and host '/etc/resolv.conf' file content is empty.
if len(l.Config.Servers) == 0 {
return nil, nil
}

if !net.ParseIP(l.Config.Servers[0]).IsLinkLocalUnicast() {
return nil, nil
}
Expand Down
9 changes: 9 additions & 0 deletions helper/link_local_dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ func testLinkLocalDNS(t *testing.T, context spec.G, it spec.S) {
Expect(ioutil.ReadFile(path)).To(Equal([]byte("test")))
})

it("do nothing if no nameservers", func() {
config := &ddns.ClientConfig{Servers: []string{}}

l := helper.LinkLocalDNS{Config: config}

Expect(l.Execute()).To(BeNil())
Expect(ioutil.ReadFile(path)).To(Equal([]byte(`test`)))
})

it("returns an error if $JAVA_SECURITY_PROPERTIES is not set", func() {
config := &ddns.ClientConfig{Servers: []string{"169.254.0.1"}}
l := helper.LinkLocalDNS{Config: config}
Expand Down

0 comments on commit 62a9f74

Please sign in to comment.