From 6ac21515ca31b16e6e4054d7f847bd0cd3b4a8c3 Mon Sep 17 00:00:00 2001 From: Matthias Hofmann Date: Thu, 14 Jun 2018 13:41:27 +0200 Subject: [PATCH] Add missing null checks. Signed-off-by: Simon Goldschmidt --- src/core/netif.c | 7 +++++++ src/core/tcp_out.c | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/netif.c b/src/core/netif.c index 4563082c..d971341c 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -500,6 +500,9 @@ void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr) { ip_addr_t old_addr; + + LWIP_ERROR("netif_set_ipaddr: invalid netif", netif != NULL, return); + /* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */ if (ipaddr == NULL) { ipaddr = IP4_ADDR_ANY4; @@ -564,6 +567,8 @@ netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask) #endif LWIP_ASSERT_CORE_LOCKED(); + LWIP_ERROR("netif_set_netmask: invalid netif", netif != NULL, return); + /* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */ if (netmask == NULL) { netmask = IP4_ADDR_ANY4; @@ -623,6 +628,8 @@ netif_set_gw(struct netif *netif, const ip4_addr_t *gw) #endif LWIP_ASSERT_CORE_LOCKED(); + LWIP_ERROR("netif_set_gw: invalid netif", netif != NULL, return); + /* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */ if (gw == NULL) { gw = IP4_ADDR_ANY4; diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 91f56aad..fde928c2 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1218,6 +1218,8 @@ tcp_build_sack_option(const struct tcp_pcb *pcb, u32_t *opts, u8_t num_sacks) static void tcp_build_wnd_scale_option(u32_t *opts) { + LWIP_ASSERT("tcp_build_wnd_scale_option: invalid opts", opts != NULL); + /* Pad with one NOP option to make everything nicely aligned */ opts[0] = PP_HTONL(0x01030300 | TCP_RCV_SCALE); } @@ -1818,7 +1820,11 @@ tcp_output_alloc_header_common(u32_t ackno, u16_t optlen, u16_t datalen, u16_t src_port, u16_t dst_port, u8_t flags, u16_t wnd) { struct tcp_hdr *tcphdr; - struct pbuf *p = pbuf_alloc(PBUF_IP, TCP_HLEN + optlen + datalen, PBUF_RAM); + struct pbuf *p; + + LWIP_ASSERT("tcp_output_alloc_header: invalid pcb", pcb != NULL); + + p = pbuf_alloc(PBUF_IP, TCP_HLEN + optlen + datalen, PBUF_RAM); if (p != NULL) { LWIP_ASSERT("check that first pbuf can hold struct tcp_hdr", (p->len >= TCP_HLEN + optlen));