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

index 4e8ddbfecf507f921f7fe3e46bdde74f8ae72d6e..e8eb5186a972a86cb560251b626da2dc909c29aa 100644 (file)
@@ -676,7 +676,9 @@ read_config(const char *file, const char *ifname, const char *ssid)
        ifo->timeout = DEFAULT_TIMEOUT;
        ifo->reboot = DEFAULT_REBOOT;
        ifo->metric = -1;
-       gethostname(ifo->hostname + 1, sizeof(ifo->hostname));
+       gethostname(ifo->hostname + 1, HOSTNAME_MAX_LEN);
+       /* Ensure that the hostname is NULL terminated */
+       ifo->hostname[HOSTNAME_MAX_LEN + 1] = '\0';
        if (strcmp(ifo->hostname + 1, "(none)") == 0 ||
            strcmp(ifo->hostname + 1, "localhost") == 0)
                ifo->hostname[1] = '\0';
index 95e83dc6547bad774ee81d9c76da5c01954a535f..5a8b8aafa9d111a1cf4ad57311b7f5923d2c55ef 100644 (file)
@@ -89,12 +89,12 @@ struct if_options {
        char **environ;
        char script[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;