Skip to content

fix: don't panic when the default interface has no DNS server - #21

Open
chbert wants to merge 1 commit into
bullfrogsec:mainfrom
chbert:fix/dns-server-detection-no-panic
Open

chbert wants to merge 1 commit into
bullfrogsec:mainfrom
chbert:fix/dns-server-detection-no-panic

Conversation

@chbert

@chbert chbert commented Sep 23, 2026

Copy link
Copy Markdown

On some third-party Ubuntu runners (seen on Depot's depot-ubuntu-latest), the agent crashes during startup:

panic: runtime error: slice bounds out of range [:-1]
  pkg/agent/network_info.go:34 GetDNSServer

resolvectl status <default-iface> returns no DNS Servers line there (DNS is configured globally, not per link), so the grep | awk output is empty and dnsServer[:len(dnsServer)-1] panics. The same slice on the ip route output panics when there is no default route.

This PR:

  • parses the resolvectl status output in Go instead of slicing raw shell output, preferring Current DNS Server over DNS Servers;
  • falls back to the global resolvectl status, then to /run/systemd/resolve/resolv.conf and /etc/resolv.conf (skipping the 127.0.0.53 stub);
  • if no upstream server is found, logs it and allows only the default DNS servers instead of crashing;
  • adds table tests for both parsers, including the empty-output case that used to panic.

GitHub-hosted runners behave the same as before: the per-link lookup still wins there.

go vet ./... and go test ./pkg/agent/ pass (linux/amd64, Go 1.26).

GetDNSServer sliced the resolvectl output with [:len-1], which panics
(slice bounds out of range [:-1]) when the default interface reports no
DNS server, as on Depot runners. Parse resolvectl output instead, fall
back to the global resolvectl status and resolv.conf, and allow only
the default DNS servers when no upstream server is found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants