Skip to content

Commit 6b41528

Browse files
rucoderOhmSpectator
authored andcommitted
Fix crash in pillar if NTP FQDN is an empty string
Under some conditions e.g. when set from Monitor TUI NTP FQDN can be an empty string which causes a crash. ResolveWithSrcIP must not crash on incorrect input pillar;panic: runtime error: index out of range -1] pillar;goroutine 170248 [running]: pillar;github.com/lf-edge/eve/pkg/pillar/devicenetwork.ResolveWithSrcIP({0x0, 0x0}, {0xc002631950, 0x10, 0x10}, {0xc002631960, 0x10, 0x10}) pillar; /pillar/devicenetwork/dns.go:79 +0x4d4 pillar;github.com/lf-edge/eve/pkg/pillar/devicenetwork.ResolveCacheWrap.func1({0x0, 0x0}, {0xc002631950, 0x10, 0x10}, {0xc002631960, 0x10, 0x10}) pillar; /pillar/devicenetwork/dns.go:122 +0x1ca pillar;github.com/lf-edge/eve/pkg/pillar/devicenetwork.ResolveWithPortsLambda.func1({0xc002631950, 0x10, 0x10}, {0xc002631960, 0x10, 0x10}) pillar; /pillar/devicenetwork/dns.go:198 +0x17b pillar;created by github.com/lf-edge/eve/pkg/pillar/devicenetwork.ResolveWithPortsLambda pillar; /pillar/devicenetwork/dns.go:182 +0x98a Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
1 parent ed6f751 commit 6b41528

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pkg/pillar/devicenetwork/dns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func ResolveWithSrcIP(domain string, dnsServerIP net.IP, srcIP net.IP) ([]DNSRes
7676
dialer := net.Dialer{LocalAddr: &sourceUDPAddr}
7777
dnsClient := dns.Client{Dialer: &dialer}
7878
msg := dns.Msg{}
79-
if domain[len(domain)-1] != '.' {
79+
if !strings.HasSuffix(domain, ".") {
8080
domain = domain + "."
8181
}
8282
msg.SetQuestion(domain, dns.TypeA)

pkg/pillar/devicenetwork/dns_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,15 @@ func TestResolveCacheWrap(t *testing.T) {
285285
t.Fatalf("resolver func should have been called twice because different src IPs, but called=%d", called)
286286
}
287287
}
288+
289+
func FuzzResolveWithSrcIP(f *testing.F) {
290+
f.Fuzz(func(t *testing.T,
291+
domain string,
292+
dnsServer string,
293+
src string,
294+
) {
295+
dnsServerIP := net.ParseIP(dnsServer)
296+
srcIP := net.ParseIP(src)
297+
devicenetwork.ResolveWithSrcIP(domain, dnsServerIP, srcIP)
298+
})
299+
}

0 commit comments

Comments
 (0)