mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-14 18:36:27 +00:00
fixed bug #34122 dhcp: hostname can overflow
This commit is contained in:
parent
bf4ec9be22
commit
c55f6b40ec
@ -41,6 +41,9 @@ HISTORY
|
|||||||
|
|
||||||
++ Bugfixes:
|
++ Bugfixes:
|
||||||
|
|
||||||
|
2011-08-24: Simon Goldschmidt
|
||||||
|
* dhcp.c: fixed bug #34122 dhcp: hostname can overflow
|
||||||
|
|
||||||
2011-08-24: Simon Goldschmidt
|
2011-08-24: Simon Goldschmidt
|
||||||
* netif.c: fixed bug #34121 netif_add/netif_set_ipaddr fail on NULL ipaddr
|
* netif.c: fixed bug #34121 netif_add/netif_set_ipaddr fail on NULL ipaddr
|
||||||
|
|
||||||
|
@ -168,6 +168,9 @@ static void dhcp_option(struct dhcp *dhcp, u8_t option_type, u8_t option_len);
|
|||||||
static void dhcp_option_byte(struct dhcp *dhcp, u8_t value);
|
static void dhcp_option_byte(struct dhcp *dhcp, u8_t value);
|
||||||
static void dhcp_option_short(struct dhcp *dhcp, u16_t value);
|
static void dhcp_option_short(struct dhcp *dhcp, u16_t value);
|
||||||
static void dhcp_option_long(struct dhcp *dhcp, u32_t value);
|
static void dhcp_option_long(struct dhcp *dhcp, u32_t value);
|
||||||
|
#if LWIP_NETIF_HOSTNAME
|
||||||
|
static void dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif);
|
||||||
|
#endif /* LWIP_NETIF_HOSTNAME */
|
||||||
/* always add the DHCP options trailer to end and pad */
|
/* always add the DHCP options trailer to end and pad */
|
||||||
static void dhcp_option_trailer(struct dhcp *dhcp);
|
static void dhcp_option_trailer(struct dhcp *dhcp);
|
||||||
|
|
||||||
@ -299,17 +302,7 @@ dhcp_select(struct netif *netif)
|
|||||||
dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER);
|
dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER);
|
||||||
|
|
||||||
#if LWIP_NETIF_HOSTNAME
|
#if LWIP_NETIF_HOSTNAME
|
||||||
if (netif->hostname != NULL) {
|
dhcp_option_hostname(dhcp, netif);
|
||||||
const char *p = (const char*)netif->hostname;
|
|
||||||
u8_t namelen = (u8_t)strlen(p);
|
|
||||||
if (namelen > 0) {
|
|
||||||
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
|
|
||||||
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
|
|
||||||
while (*p) {
|
|
||||||
dhcp_option_byte(dhcp, *p++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* LWIP_NETIF_HOSTNAME */
|
#endif /* LWIP_NETIF_HOSTNAME */
|
||||||
|
|
||||||
dhcp_option_trailer(dhcp);
|
dhcp_option_trailer(dhcp);
|
||||||
@ -1029,17 +1022,7 @@ dhcp_renew(struct netif *netif)
|
|||||||
dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
|
dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
|
||||||
|
|
||||||
#if LWIP_NETIF_HOSTNAME
|
#if LWIP_NETIF_HOSTNAME
|
||||||
if (netif->hostname != NULL) {
|
dhcp_option_hostname(dhcp, netif);
|
||||||
const char *p = (const char*)netif->hostname;
|
|
||||||
u8_t namelen = (u8_t)strlen(p);
|
|
||||||
if (namelen > 0) {
|
|
||||||
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
|
|
||||||
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
|
|
||||||
while (*p) {
|
|
||||||
dhcp_option_byte(dhcp, *p++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* LWIP_NETIF_HOSTNAME */
|
#endif /* LWIP_NETIF_HOSTNAME */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -1092,17 +1075,7 @@ dhcp_rebind(struct netif *netif)
|
|||||||
dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
|
dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
|
||||||
|
|
||||||
#if LWIP_NETIF_HOSTNAME
|
#if LWIP_NETIF_HOSTNAME
|
||||||
if (netif->hostname != NULL) {
|
dhcp_option_hostname(dhcp, netif);
|
||||||
const char *p = (const char*)netif->hostname;
|
|
||||||
u8_t namelen = (u8_t)strlen(p);
|
|
||||||
if (namelen > 0) {
|
|
||||||
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
|
|
||||||
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
|
|
||||||
while (*p) {
|
|
||||||
dhcp_option_byte(dhcp, *p++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* LWIP_NETIF_HOSTNAME */
|
#endif /* LWIP_NETIF_HOSTNAME */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -1314,6 +1287,26 @@ dhcp_option_long(struct dhcp *dhcp, u32_t value)
|
|||||||
dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0x000000ffUL));
|
dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0x000000ffUL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LWIP_NETIF_HOSTNAME
|
||||||
|
static void
|
||||||
|
dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif)
|
||||||
|
{
|
||||||
|
if (netif->hostname != NULL) {
|
||||||
|
size_t namelen = strlen(netif->hostname);
|
||||||
|
if (namelen > 0) {
|
||||||
|
u8_t len;
|
||||||
|
const char *p = netif->hostname;
|
||||||
|
LWIP_ASSERT("DHCP: hostname is too long!", namelen <= 255);
|
||||||
|
len = LWIP_MAX(namelen, 255);
|
||||||
|
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, len);
|
||||||
|
while (len--) {
|
||||||
|
dhcp_option_byte(dhcp, *p++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* LWIP_NETIF_HOSTNAME */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the DHCP message and the DHCP options.
|
* Extract the DHCP message and the DHCP options.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user