Skip to content

Commit

Permalink
Fix sending NACK, use helper function to fill pbuf
Browse files Browse the repository at this point in the history
As noticed in esp8266#8582 (comment)
Plus, handle the case when `pbuf->len` is less than struct size
  • Loading branch information
mcspr committed Jun 14, 2022
1 parent 8bfc2e9 commit 98c2837
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions cores/esp8266/LwipDhcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ DhcpServer::OptionsBuffer DhcpServer::create_msg(struct dhcps_msg* m)
///////////////////////////////////////////////////////////////////////////////////
void DhcpServer::send_offer(struct dhcps_msg* m)
{
struct pbuf *p, *q;
struct pbuf *p;

auto options = create_msg(m);
options.add(DHCP_OPTION_MSG_TYPE, DHCPOFFER);
Expand All @@ -438,12 +438,7 @@ void DhcpServer::send_offer(struct dhcps_msg* m)
os_printf("dhcps: send_offer>>p->tot_len = %d\n", p->tot_len);
os_printf("dhcps: send_offer>>p->len = %d\n", p->len);
#endif
q = p;
while (q != nullptr)
{
std::memcpy((u8_t*)q->payload, reinterpret_cast<u8_t*>(&m), q->len);
q = q->next;
}
pbuf_take(p, m, sizeof(struct dhcps_msg));
}
else
{
Expand Down Expand Up @@ -475,7 +470,7 @@ void DhcpServer::send_offer(struct dhcps_msg* m)
///////////////////////////////////////////////////////////////////////////////////
void DhcpServer::send_nak(struct dhcps_msg* m)
{
struct pbuf *p, *q;
struct pbuf *p;

auto options = create_msg(m);
options.add(DHCP_OPTION_MSG_TYPE, DHCPNAK);
Expand All @@ -492,12 +487,7 @@ void DhcpServer::send_nak(struct dhcps_msg* m)
os_printf("dhcps: send_nak>>p->tot_len = %d\n", p->tot_len);
os_printf("dhcps: send_nak>>p->len = %d\n", p->len);
#endif
q = p;
while (q != nullptr)
{
std::memcpy((u8_t*)q->payload, (u8_t*)m, q->len);
q = q->next;
}
pbuf_take(p, m, sizeof(struct dhcps_msg));
}
else
{
Expand All @@ -524,7 +514,7 @@ void DhcpServer::send_nak(struct dhcps_msg* m)
///////////////////////////////////////////////////////////////////////////////////
void DhcpServer::send_ack(struct dhcps_msg* m)
{
struct pbuf *p, *q;
struct pbuf *p;

auto options = create_msg(m);
options.add(DHCP_OPTION_MSG_TYPE, DHCPACK);
Expand All @@ -548,12 +538,7 @@ void DhcpServer::send_ack(struct dhcps_msg* m)
os_printf("dhcps: send_ack>>p->tot_len = %d\n", p->tot_len);
os_printf("dhcps: send_ack>>p->len = %d\n", p->len);
#endif
q = p;
while (q != nullptr)
{
std::memcpy((u8_t*)q->payload, (u8_t*)m, q->len);
q = q->next;
}
pbuf_take(p, m, sizeof(struct dhcps_msg));
}
else
{
Expand Down

0 comments on commit 98c2837

Please sign in to comment.