-
Type:
Problem report
-
Resolution: Duplicate
-
Priority:
Trivial
-
None
-
Affects Version/s: 7.0.32, 7.4.16
-
Component/s: None
-
None
Description
Zabbix agent 2 on Windows crashes with a Go panic when it checks net.dns, net.dns.record or net.dns.perf with an empty first parameter (system DNS server), and none of the network adapters is up, e.g. the cable is unplugged or Wi-Fi is disconnected. The agent service stops. The agent log has nothing about the crash. The stack trace is visible only when the agent runs in the foreground from cmd.exe.
Affected versions: at least 6.0.48 - 7.0.31.
Steps to reproduce
- Windows host with Zabbix agent 2. A Zabbix server is not needed, the issue reproduces with -t.
- Disconnect all network adapters (unplug the cable / turn off Wi-Fi). No other adapter (VPN, Hyper-V vEthernet etc.) should be up with DNS servers configured.
- Run:
zabbix_agent2.exe -t "net.dns[,google.com,A]"
Result: the agent panics (index out of range [0] with length 0). If the same item is an active check, the running agent service crashes.
Expected: the item becomes not supported, for example with "no dns server found", and the agent keeps running.
Cause
The bug is in src/go/plugins/net/dns/dns_windows.go, setDefaultIP(). The function collects DNS servers only from adapters with OperStatus == IfOperStatusUp. When no adapter is up, servers is empty. The check for an empty list compares with < 0, so it is never true, and servers[0] panics:
if len(servers) < 0 { // always false return zbxerr.New("no dns server found") } return o.setIP(servers[0]) // panic when len(servers) == 0
Fix: if len(servers) == 0.
The same code is in release/6.0, release/7.0, release/7.4 and master.
The Linux implementation (dns_nix.go) is not affected: it returns "Cannot find default dns nameserver." Checked on agent 2 7.0.30 (Linux, Docker): with no network and with no nameserver in /etc/resolv.conf, both in -t mode and as active checks, the item becomes not supported and the agent does not crash.
Workaround
Set the DNS server explicitly in the first parameter, for example net.dns[8.8.8.8,google.com,A].