reference: terminate string returned by gethostname()

POSIX doesn't require the string to be terminated if it didn't fit in
the buffer.

This issue was found in a Frama-C analysis.
This commit is contained in:
Miroslav Lichvar 2018-06-20 12:27:59 +02:00
parent 63fe34e890
commit 49cdd6bf09

View file

@ -545,6 +545,8 @@ maybe_log_offset(double offset, time_t now)
if (gethostname(host, sizeof(host)) < 0) {
strcpy(host, "<UNKNOWN>");
}
host[sizeof (host) - 1] = '\0';
fprintf(p, "Subject: chronyd reports change to system clock on node [%s]\n", host);
fputs("\n", p);