diff --git a/ndhc/config.h b/ndhc/config.h index 0a3cc9e..10cd4ce 100644 --- a/ndhc/config.h +++ b/ndhc/config.h @@ -30,6 +30,7 @@ #define NDHC_CONFIG_H_ #include +#include struct client_state_t { unsigned long long leaseStartTime; @@ -51,7 +52,7 @@ struct client_config_t { char abort_if_no_lease; // Abort if no lease char background_if_no_lease; // Fork to background if no lease char clientid_mac; // If true, then the clientid is a MAC addr - char *interface; // The name of the interface to use + char interface[IFNAMSIZ]; // The name of the interface to use char clientid[64]; // Optional client id to use char hostname[64]; // Optional hostname to use char vendor[64]; // Vendor identification that will be sent diff --git a/ndhc/ndhc.c b/ndhc/ndhc.c index 6f5665b..6da240a 100644 --- a/ndhc/ndhc.c +++ b/ndhc/ndhc.c @@ -399,7 +399,8 @@ int main(int argc, char **argv) sizeof client_config.hostname); break; case 'i': - client_config.interface = optarg; + strnkcpy(client_config.interface, optarg, + sizeof client_config.interface); break; case 'n': client_config.abort_if_no_lease = 1; diff --git a/ndhc/netlink.c b/ndhc/netlink.c index d63ce4c..9d246d5 100644 --- a/ndhc/netlink.c +++ b/ndhc/netlink.c @@ -58,7 +58,9 @@ static void get_if_index_and_mac(const struct nlmsghdr *nlh, nl_attr_parse(nlh, sizeof *ifm, nlrtattr_assign, tb); if (!tb[IFLA_IFNAME]) return; - if (!strcmp(client_config.interface, nlattr_get_data(tb[IFLA_IFNAME]))) { + if (!strncmp(client_config.interface, + nlattr_get_data(tb[IFLA_IFNAME]), + sizeof client_config.interface)) { client_config.ifindex = ifm->ifi_index; if (!tb[IFLA_ADDRESS]) suicide("FATAL: Adapter %s lacks a hardware address.");