From 45cb8dd9beb277655297ecb053b40240fdc30621 Mon Sep 17 00:00:00 2001 From: Sergey Nechaev Date: Sat, 14 May 2016 21:36:15 +0100 Subject: [PATCH] Stricter command line args validation to dhcp_release6. --- contrib/lease-tools/dhcp_release6.c | 41 ++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/contrib/lease-tools/dhcp_release6.c b/contrib/lease-tools/dhcp_release6.c index 74fb26a4..00ff1154 100644 --- a/contrib/lease-tools/dhcp_release6.c +++ b/contrib/lease-tools/dhcp_release6.c @@ -350,11 +350,12 @@ int send_release_packet(const char* iface, struct dhcp6_packet* packet){ int main(int argc, char * const argv[]) { - const char* iface = ""; - const char* ip = ""; - const char* client_id = ""; - const char* server_id = ""; - const char* iaid = ""; + const char* UNINITIALIZED = ""; + const char* iface = UNINITIALIZED; + const char* ip = UNINITIALIZED; + const char* client_id = UNINITIALIZED; + const char* server_id = UNINITIALIZED; + const char* iaid = UNINITIALIZED; int dry_run = 0; while (1) { int option_index = 0; @@ -392,7 +393,7 @@ int main(int argc, char * const argv[]) { break; case 'h': usage(argv[0], stdout); - break; + return 0; case '?': usage(argv[0], stderr); return -1; @@ -402,6 +403,34 @@ int main(int argc, char * const argv[]) { } } + if (iaid == UNINITIALIZED){ + fprintf(stderr, "Missing required iaid parameter\n"); + usage(argv[0], stderr); + return -1; + } + if (server_id == UNINITIALIZED){ + fprintf(stderr, "Missing required server-id parameter\n"); + usage(argv[0], stderr); + return -1; + } + if (client_id == UNINITIALIZED){ + fprintf(stderr, "Missing required client-id parameter\n"); + usage(argv[0], stderr); + return -1; + } + if (ip == UNINITIALIZED){ + fprintf(stderr, "Missing required ip parameter\n"); + usage(argv[0], stderr); + return -1; + } + if (iface == UNINITIALIZED){ + fprintf(stderr, "Missing required iface parameter\n"); + usage(argv[0], stderr); + return -1; + } + + + struct dhcp6_packet packet = create_release_packet(iaid, ip, client_id, server_id); if (dry_run){ uint16_t i;