Minor improvements in lease-tools

Limit max interface name to fit into buffer.
Make sure pointer have to be always positive.
Close socket after received reply.
This commit is contained in:
Petr Menšík
2018-08-17 10:20:05 +02:00
committed by Simon Kelley
parent 282eab7952
commit 2b38e3823b
3 changed files with 7 additions and 3 deletions

View File

@@ -270,7 +270,8 @@ int main(int argc, char **argv)
/* This voodoo fakes up a packet coming from the correct interface, which really matters for
a DHCP server */
strcpy(ifr.ifr_name, argv[1]);
strncpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name)-1);
ifr.ifr_name[sizeof(ifr.ifr_name)-1] = '\0';
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) == -1)
{
perror("cannot setup interface");