Skip to content

Commit 216b820

Browse files
devsaurusmarcelstoer
authored andcommitted
Ensure standard DHCP message length when sending response to clients (#1985)
1 parent 2c55358 commit 216b820

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

app/include/lwip/app/dhcpserver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#define USE_DNS
77

8+
#define DHCP_MSGOPTIONS_MIN_LEN 312
9+
810
typedef struct dhcps_state{
911
sint16_t state;
1012
} dhcps_state;

app/lwip/app/dhcpserver.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ static void ICACHE_FLASH_ATTR send_offer(struct dhcps_msg *m)
298298
end = add_offer_options(end);
299299
end = add_end(end);
300300

301-
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
301+
// ensure that not more than the minimum options length is transmitted
302+
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg) - sizeof(m->options) + DHCP_MSGOPTIONS_MIN_LEN, PBUF_RAM);
302303
#if DHCPS_DEBUG
303304
os_printf("udhcp: send_offer>>p->ref = %d\n", p->ref);
304305
#endif
@@ -358,7 +359,8 @@ static void ICACHE_FLASH_ATTR send_nak(struct dhcps_msg *m)
358359
end = add_msg_type(&m->options[4], DHCPNAK);
359360
end = add_end(end);
360361

361-
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
362+
// ensure that not more than the minimum options length is transmitted
363+
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg) - sizeof(m->options) + DHCP_MSGOPTIONS_MIN_LEN, PBUF_RAM);
362364
#if DHCPS_DEBUG
363365
os_printf("udhcp: send_nak>>p->ref = %d\n", p->ref);
364366
#endif
@@ -418,8 +420,9 @@ static void ICACHE_FLASH_ATTR send_ack(struct dhcps_msg *m)
418420
end = add_msg_type(&m->options[4], DHCPACK);
419421
end = add_offer_options(end);
420422
end = add_end(end);
421-
422-
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
423+
424+
// ensure that not more than the minimum options length is transmitted
425+
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg) - sizeof(m->options) + DHCP_MSGOPTIONS_MIN_LEN, PBUF_RAM);
423426
#if DHCPS_DEBUG
424427
os_printf("udhcp: send_ack>>p->ref = %d\n", p->ref);
425428
#endif

0 commit comments

Comments
 (0)