]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Ensure that we have enough buffer for gethostname and terminate it correctly. v4.0.8
authorRoy Marples <roy@marples.name>
Mon, 26 Jan 2009 09:14:54 +0000 (09:14 +0000)
committerRoy Marples <roy@marples.name>
Mon, 26 Jan 2009 09:14:54 +0000 (09:14 +0000)
dhcpcd.c
dhcpcd.h

index 93d8b8d669178c81c051ac42a99a65a986c36706..58321ef77b68dd358ed92b5cc2bf77c630374acb 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -648,7 +648,9 @@ main(int argc, char **argv)
        }
 #endif
 
-       gethostname(options->hostname + 1, sizeof(options->hostname));
+       gethostname(options->hostname + 1, HOSTNAME_MAX_LEN);
+       /* Ensure that the hostname is NULL terminated */ 
+       options->hostname[HOSTNAME_MAX_LEN + 1] = '\0';
        if (strcmp(options->hostname + 1, "(none)") == 0 ||
            strcmp(options->hostname + 1, "localhost") == 0)
                options->hostname[1] = '\0';
index 1cd2b5d5ffac36d4ebbcec1d996e30fd512ae2fd..0aeffaed9f2189ad737a68a77e9f848d46ce204e 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -82,12 +82,12 @@ struct options {
        char script[PATH_MAX];
        char pidfile[PATH_MAX];
 
-       char hostname[HOSTNAME_MAX_LEN + 1];
+       char hostname[HOSTNAME_MAX_LEN + 2];
        int fqdn;
-       uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 1];
-       char clientid[CLIENTID_MAX_LEN + 1];
-       uint8_t userclass[USERCLASS_MAX_LEN + 1];
-       uint8_t vendor[VENDOR_MAX_LEN + 1];
+       uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
+       char clientid[CLIENTID_MAX_LEN + 2];
+       uint8_t userclass[USERCLASS_MAX_LEN + 2];
+       uint8_t vendor[VENDOR_MAX_LEN + 2];
 
        size_t blacklist_len;
        in_addr_t *blacklist;