]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
reference: terminate string returned by gethostname()
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 20 Jun 2018 10:27:59 +0000 (12:27 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 20 Jun 2018 14:45:21 +0000 (16:45 +0200)
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.

reference.c

index dbc40e7043c5a6b1ed285bab67fd8ae5d1795117..0ae7ab2d1848af47853df884087957e868cae5ad 100644 (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);