[9.20] fix: dev: Fix inverted gethostname() check in rndc status

The replacement of named_os_gethostname() with raw gethostname()
inverted the success check: the "localhost" fallback runs on success,
and on failure the uninitialized hostname buffer is read by snprintf(),
leaking stack memory via the rndc status reply.

Closes #5889

Backport of MR !11879

Merge branch 'backport-5889-fix-gethostname-inverted-check-9.20' into 'bind-9.20'

See merge request isc-projects/bind9!11881
This commit is contained in:
Ondřej Surý 2026-04-17 18:46:53 +02:00
commit 5ede4a87eb

View file

@ -12660,7 +12660,7 @@ named_server_status(named_server_t *server, isc_buffer_t **text) {
cb);
CHECK(putstr(text, line));
if (gethostname(hostname, sizeof(hostname)) == 0) {
if (gethostname(hostname, sizeof(hostname)) != 0) {
strlcpy(hostname, "localhost", sizeof(hostname));
}
snprintf(line, sizeof(line), "running on %s: %s\n", hostname,