]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Ensure our derived hostname is NULL terminated.
authorRoy Marples <roy@marples.name>
Wed, 5 Jun 2013 16:35:54 +0000 (16:35 +0000)
committerRoy Marples <roy@marples.name>
Wed, 5 Jun 2013 16:35:54 +0000 (16:35 +0000)
common.c

index 4f277958e2cae4b5183e3a2634dab7119271fd79..1740e29e9022a4d1b1c5ec8168a0b210abdd11bb 100644 (file)
--- a/common.c
+++ b/common.c
@@ -60,7 +60,7 @@
 #  define _PATH_DEVNULL "/dev/null"
 #endif
 
-static char hostname_buffer[HOSTNAME_MAX_LEN];
+static char hostname_buffer[HOSTNAME_MAX_LEN + 1];
 int clock_monotonic;
 static char *lbuf;
 static size_t lbuf_len;
@@ -140,6 +140,7 @@ get_hostname(void)
 {
 
        gethostname(hostname_buffer, sizeof(hostname_buffer));
+       hostname_buffer[sizeof(hostname_buffer) - 1] = '\0';
        if (strcmp(hostname_buffer, "(none)") == 0 ||
            strcmp(hostname_buffer, "localhost") == 0 ||
            strncmp(hostname_buffer, "localhost.", strlen("localhost.")) == 0 ||