From 216b820d08ed4c1fc189b00ad3ed7e3b86616f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnim=20L=C3=A4uger?= Date: Thu, 25 May 2017 13:59:45 +0200 Subject: [PATCH] Ensure standard DHCP message length when sending response to clients (#1985) --- app/include/lwip/app/dhcpserver.h | 2 ++ app/lwip/app/dhcpserver.c | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/include/lwip/app/dhcpserver.h b/app/include/lwip/app/dhcpserver.h index 1edbc38b..d62b5f40 100644 --- a/app/include/lwip/app/dhcpserver.h +++ b/app/include/lwip/app/dhcpserver.h @@ -5,6 +5,8 @@ #define USE_DNS +#define DHCP_MSGOPTIONS_MIN_LEN 312 + typedef struct dhcps_state{ sint16_t state; } dhcps_state; diff --git a/app/lwip/app/dhcpserver.c b/app/lwip/app/dhcpserver.c index 1353e702..b4ad7e83 100755 --- a/app/lwip/app/dhcpserver.c +++ b/app/lwip/app/dhcpserver.c @@ -298,7 +298,8 @@ static void ICACHE_FLASH_ATTR send_offer(struct dhcps_msg *m) end = add_offer_options(end); end = add_end(end); - p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM); + // ensure that not more than the minimum options length is transmitted + p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg) - sizeof(m->options) + DHCP_MSGOPTIONS_MIN_LEN, PBUF_RAM); #if DHCPS_DEBUG os_printf("udhcp: send_offer>>p->ref = %d\n", p->ref); #endif @@ -358,7 +359,8 @@ static void ICACHE_FLASH_ATTR send_nak(struct dhcps_msg *m) end = add_msg_type(&m->options[4], DHCPNAK); end = add_end(end); - p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM); + // ensure that not more than the minimum options length is transmitted + p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg) - sizeof(m->options) + DHCP_MSGOPTIONS_MIN_LEN, PBUF_RAM); #if DHCPS_DEBUG os_printf("udhcp: send_nak>>p->ref = %d\n", p->ref); #endif @@ -418,8 +420,9 @@ static void ICACHE_FLASH_ATTR send_ack(struct dhcps_msg *m) end = add_msg_type(&m->options[4], DHCPACK); end = add_offer_options(end); end = add_end(end); - - p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM); + + // ensure that not more than the minimum options length is transmitted + p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg) - sizeof(m->options) + DHCP_MSGOPTIONS_MIN_LEN, PBUF_RAM); #if DHCPS_DEBUG os_printf("udhcp: send_ack>>p->ref = %d\n", p->ref); #endif