From 2b38e3823b12ab13f86c3a44648de436daadb1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= Date: Fri, 17 Aug 2018 10:20:05 +0200 Subject: [PATCH] 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. --- contrib/lease-tools/dhcp_lease_time.c | 2 +- contrib/lease-tools/dhcp_release.c | 3 ++- contrib/lease-tools/dhcp_release6.c | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/contrib/lease-tools/dhcp_lease_time.c b/contrib/lease-tools/dhcp_lease_time.c index f9d7a85..697d627 100644 --- a/contrib/lease-tools/dhcp_lease_time.c +++ b/contrib/lease-tools/dhcp_lease_time.c @@ -83,7 +83,7 @@ static unsigned char *option_find1(unsigned char *p, unsigned char *end, int opt if (p >= end - 2) return NULL; /* malformed packet */ opt_len = option_len(p); - if (p >= end - (2 + opt_len)) + if (end - p >= (2 + opt_len)) return NULL; /* malformed packet */ if (*p == opt && opt_len >= minsize) return p; diff --git a/contrib/lease-tools/dhcp_release.c b/contrib/lease-tools/dhcp_release.c index 201fcd3..59883d4 100644 --- a/contrib/lease-tools/dhcp_release.c +++ b/contrib/lease-tools/dhcp_release.c @@ -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"); diff --git a/contrib/lease-tools/dhcp_release6.c b/contrib/lease-tools/dhcp_release6.c index 7f79fa7..d680222 100644 --- a/contrib/lease-tools/dhcp_release6.c +++ b/contrib/lease-tools/dhcp_release6.c @@ -376,9 +376,12 @@ int send_release_packet(const char* iface, struct dhcp6_packet* packet) sleep(1); continue; } + + close(sock); return result; } - + + close(sock); fprintf(stderr, "Response timed out\n"); return -1; }