From: Roy Marples Date: Mon, 26 Jan 2009 09:11:38 +0000 (+0000) Subject: Ensure that we have enough buffer for gethostname and terminate it correctly. X-Git-Tag: v5.0.0~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fb0c27c39d95db8fd8d4da3a3fb552d79f20613;p=thirdparty%2Fdhcpcd.git Ensure that we have enough buffer for gethostname and terminate it correctly. --- diff --git a/if-options.c b/if-options.c index 4e8ddbfe..e8eb5186 100644 --- a/if-options.c +++ b/if-options.c @@ -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'; diff --git a/if-options.h b/if-options.h index 95e83dc6..5a8b8aaf 100644 --- a/if-options.h +++ b/if-options.h @@ -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;