From 43b18b20ccd9f12f966745bed400aad5af7ef155 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 28 Aug 2015 10:15:57 +0200 Subject: [PATCH] fixed bug #45818: API functions should check if type of ip_addr_t parameter matches the pcb type --- src/core/tcp.c | 8 ++++++++ src/core/udp.c | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/core/tcp.c b/src/core/tcp.c index 6c18d76f..eff39917 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -450,6 +450,10 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) int max_pcb_list = NUM_TCP_PCB_LISTS; struct tcp_pcb *cpcb; + if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) { + return ERR_VAL; + } + LWIP_ERROR("tcp_bind: can only bind in state CLOSED", pcb->state == CLOSED, return ERR_VAL); #if SO_REUSE @@ -756,6 +760,10 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, ip_addr_t local_ip_tmp; #endif /* LWIP_IPV4 && LWIP_IPV6 */ + if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) { + return ERR_VAL; + } + LWIP_ERROR("tcp_connect: can only connect from state CLOSED", pcb->state == CLOSED, return ERR_ISCONN); LWIP_DEBUGF(TCP_DEBUG, ("tcp_connect to port %"U16_F"\n", port)); diff --git a/src/core/udp.c b/src/core/udp.c index 79abc0d4..c902f755 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -557,6 +557,10 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, ip_addr_t dst_ip_tmp; #endif /* LWIP_IPV6 && LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS */ + if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) { + return ERR_VAL; + } + LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send\n")); #if LWIP_IPV6 || (LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS) @@ -639,6 +643,10 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_i ip_addr_t src_ip_tmp; #endif /* LWIP_IPV6 && LWIP_IPV4 */ + if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) { + return ERR_VAL; + } + /* PCB local address is IP_ANY_ADDR? */ #if LWIP_IPV6 if (PCB_ISIPV6(pcb)) { @@ -705,6 +713,11 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d u8_t ip_proto; u8_t ttl; + if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) || + !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) { + return ERR_VAL; + } + #if LWIP_IPV4 && IP_SOF_BROADCAST /* broadcast filter? */ if (!ip_get_option(pcb, SOF_BROADCAST) && @@ -901,6 +914,10 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) struct udp_pcb *ipcb; u8_t rebind; + if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) { + return ERR_VAL; + } + LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = ")); ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_TRACE, ipaddr); LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, (", port = %"U16_F")\n", port)); @@ -986,6 +1003,10 @@ udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) { struct udp_pcb *ipcb; + if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) { + return ERR_VAL; + } + if (pcb->local_port == 0) { err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port); if (err != ERR_OK) {