Add null pointer checks for TCP, UDP and netif

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
This commit is contained in:
Matthias Hofmann 2018-06-12 10:24:08 +02:00 committed by Simon Goldschmidt
parent 6ea2483546
commit 342d0eadfb
5 changed files with 228 additions and 30 deletions

View File

@ -150,6 +150,8 @@ static struct netif loop_netif;
static err_t
netif_loopif_init(struct netif *netif)
{
LWIP_ASSERT("netif_loopif_init: invalid netif", netif != NULL);
/* initialize the snmp variables and counters inside the struct netif
* ifSpeed: no assumption can be made!
*/
@ -216,6 +218,9 @@ netif_input(struct pbuf *p, struct netif *inp)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif_input: invalid pbuf", p != NULL);
LWIP_ASSERT("netif_input: invalid netif", inp != NULL);
#if LWIP_ETHERNET
if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {
return ethernet_input(p, inp);
@ -287,7 +292,9 @@ netif_add(struct netif *netif,
}
#endif
LWIP_ASSERT("No init function given", init != NULL);
LWIP_ERROR("netif_add: invalid netif", netif != NULL, return NULL);
LWIP_ERROR("netif_add: No init function given", init != NULL, return NULL);
LWIP_ERROR("netif_add: No input function given", input != NULL, return NULL);
#if LWIP_IPV4
if (ipaddr == NULL) {
@ -826,6 +833,8 @@ netif_set_up(struct netif *netif)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif_set_up: invalid netif", netif != NULL, return);
if (!(netif->flags & NETIF_FLAG_UP)) {
netif_set_flags(netif, NETIF_FLAG_UP);
@ -853,6 +862,8 @@ netif_set_up(struct netif *netif)
static void
netif_issue_reports(struct netif *netif, u8_t report_type)
{
LWIP_ASSERT("netif_issue_reports: invalid netif", netif != NULL);
/* Only send reports when both link and admin states are up */
if (!(netif->flags & NETIF_FLAG_LINK_UP) ||
!(netif->flags & NETIF_FLAG_UP)) {
@ -897,6 +908,8 @@ netif_set_down(struct netif *netif)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif_set_down: invalid netif", netif != NULL, return);
if (netif->flags & NETIF_FLAG_UP) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
{
@ -964,6 +977,8 @@ netif_set_link_up(struct netif *netif)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif_set_link_up: invalid netif", netif != NULL, return);
if (!(netif->flags & NETIF_FLAG_LINK_UP)) {
netif_set_flags(netif, NETIF_FLAG_LINK_UP);
@ -1000,6 +1015,8 @@ netif_set_link_down(struct netif *netif )
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif_set_link_down: invalid netif", netif != NULL, return);
if (netif->flags & NETIF_FLAG_LINK_UP) {
netif_clear_flags(netif, NETIF_FLAG_LINK_UP);
NETIF_LINK_CALLBACK(netif);
@ -1067,6 +1084,9 @@ netif_loop_output(struct netif *netif, struct pbuf *p)
#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
SYS_ARCH_DECL_PROTECT(lev);
LWIP_ASSERT("netif_loop_output: invalid netif", netif != NULL);
LWIP_ASSERT("netif_loop_output: invalid pbuf", p != NULL);
/* Allocate a new pbuf */
r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
if (r == NULL) {
@ -1176,6 +1196,8 @@ netif_poll(struct netif *netif)
#endif /* MIB2_STATS */
SYS_ARCH_DECL_PROTECT(lev);
LWIP_ASSERT("netif_poll: invalid netif", netif != NULL);
/* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is protected */
SYS_ARCH_PROTECT(lev);
while (netif->loop_first != NULL) {
@ -1279,10 +1301,11 @@ netif_alloc_client_data_id(void)
void
netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6)
{
LWIP_ASSERT("addr6 != NULL", addr6 != NULL);
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif_ip6_addr_set: invalid netif", netif != NULL);
LWIP_ASSERT("netif_ip6_addr_set: invalid addr6", addr6 != NULL);
netif_ip6_addr_set_parts(netif, addr_idx, addr6->addr[0], addr6->addr[1],
addr6->addr[2], addr6->addr[3]);
}
@ -1432,6 +1455,9 @@ netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr)
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif_get_ip6_addr_match: invalid netif", netif != NULL);
LWIP_ASSERT("netif_get_ip6_addr_match: invalid ip6addr", ip6addr != NULL);
#if LWIP_IPV6_SCOPES
if (ip6_addr_has_zone(ip6addr) && !ip6_addr_test_zone(ip6addr, netif)) {
return -1; /* wrong zone, no match */
@ -1462,6 +1488,8 @@ netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit)
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif_create_ip6_linklocal_address: invalid netif", netif != NULL);
/* Link-local prefix. */
ip_2_ip6(&netif->ip6_addr[0])->addr[0] = PP_HTONL(0xfe800000ul);
ip_2_ip6(&netif->ip6_addr[0])->addr[1] = 0;
@ -1528,6 +1556,9 @@ netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chos
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif_add_ip6_address: invalid netif", netif != NULL);
LWIP_ASSERT("netif_add_ip6_address: invalid ip6addr", ip6addr != NULL);
i = netif_get_ip6_addr_match(netif, ip6addr);
if (i >= 0) {
/* Address already added */

View File

@ -251,6 +251,10 @@ static void
tcp_remove_listener(struct tcp_pcb *list, struct tcp_pcb_listen *lpcb)
{
struct tcp_pcb *pcb;
LWIP_ASSERT("tcp_remove_listener: invalid pcb list", list != NULL);
LWIP_ASSERT("tcp_remove_listener: invalid listener", lpcb != NULL);
for (pcb = list; pcb != NULL; pcb = pcb->next) {
if (pcb->listener == lpcb) {
pcb->listener = NULL;
@ -344,6 +348,8 @@ tcp_backlog_accepted(struct tcp_pcb *pcb)
static err_t
tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
{
LWIP_ASSERT("tcp_close_shutdown: invalid pcb", pcb != NULL);
if (rst_on_unacked_data && ((pcb->state == ESTABLISHED) || (pcb->state == CLOSE_WAIT))) {
if ((pcb->refused_data != NULL) || (pcb->rcv_wnd != TCP_WND_MAX(pcb))) {
/* Not all data received by application, send RST to tell the remote
@ -478,8 +484,11 @@ tcp_close_shutdown_fin(struct tcp_pcb *pcb)
err_t
tcp_close(struct tcp_pcb *pcb)
{
LWIP_DEBUGF(TCP_DEBUG, ("tcp_close: closing in "));
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("tcp_close: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_DEBUGF(TCP_DEBUG, ("tcp_close: closing in "));
tcp_debug_print_state(pcb->state);
if (pcb->state != LISTEN) {
@ -507,6 +516,9 @@ err_t
tcp_shutdown(struct tcp_pcb *pcb, int shut_rx, int shut_tx)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("tcp_shutdown: invalid pcb", pcb != NULL, return ERR_ARG);
if (pcb->state == LISTEN) {
return ERR_CONN;
}
@ -558,6 +570,9 @@ tcp_abandon(struct tcp_pcb *pcb, int reset)
void *errf_arg;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("tcp_abandon: invalid pcb", pcb != NULL, return);
/* pcb->state LISTEN not allowed here */
LWIP_ASSERT("don't call tcp_abort/tcp_abandon for listen-pcbs",
pcb->state != LISTEN);
@ -661,9 +676,8 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
#endif /* LWIP_IPV4 */
/* still need to check for ipaddr == NULL in IPv6 only case */
if ((pcb == NULL) || (ipaddr == NULL)) {
return ERR_VAL;
}
LWIP_ERROR("tcp_bind: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_ERROR("tcp_bind: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
LWIP_ERROR("tcp_bind: can only bind in state CLOSED", pcb->state == CLOSED, return ERR_VAL);
@ -761,6 +775,8 @@ tcp_accept_null(void *arg, struct tcp_pcb *pcb, err_t err)
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(err);
LWIP_ASSERT("tcp_accept_null: invalid pcb", pcb != NULL);
tcp_abort(pcb);
return ERR_ABRT;
@ -830,8 +846,11 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
err_t res;
LWIP_UNUSED_ARG(backlog);
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("tcp_listen: pcb already connected", pcb->state == CLOSED, res = ERR_CLSD; goto done);
LWIP_ERROR("tcp_listen_with_backlog_and_err: invalid pcb", pcb != NULL, res = ERR_ARG; goto done);
LWIP_ERROR("tcp_listen_with_backlog_and_err: pcb already connected", pcb->state == CLOSED, res = ERR_CLSD; goto done);
/* already listening? */
if (pcb->state == LISTEN) {
@ -905,7 +924,10 @@ done:
u32_t
tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)
{
u32_t new_right_edge = pcb->rcv_nxt + pcb->rcv_wnd;
u32_t new_right_edge;
LWIP_ASSERT("tcp_update_rcv_ann_wnd: invalid pcb", pcb != NULL);
new_right_edge = pcb->rcv_nxt + pcb->rcv_wnd;
if (TCP_SEQ_GEQ(new_right_edge, pcb->rcv_ann_right_edge + LWIP_MIN((TCP_WND / 2), pcb->mss))) {
/* we can advertise more window */
@ -943,6 +965,9 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len)
u32_t wnd_inflation;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("tcp_recved: invalid pcb", pcb != NULL, return);
/* pcb->state LISTEN not allowed here */
LWIP_ASSERT("don't call tcp_recved for listen-pcbs",
pcb->state != LISTEN);
@ -1049,9 +1074,8 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
LWIP_ASSERT_CORE_LOCKED();
if ((pcb == NULL) || (ipaddr == NULL)) {
return ERR_VAL;
}
LWIP_ERROR("tcp_connect: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_ERROR("tcp_connect: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
LWIP_ERROR("tcp_connect: can only connect from state CLOSED", pcb->state == CLOSED, return ERR_ISCONN);
@ -1510,6 +1534,8 @@ tcp_txnow(void)
err_t
tcp_process_refused_data(struct tcp_pcb *pcb)
{
LWIP_ERROR("tcp_process_refused_data: invalid pcb", pcb != NULL, return ERR_ARG);
#if TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
struct pbuf *rest;
while (pcb->refused_data != NULL)
@ -1611,6 +1637,9 @@ void
tcp_setprio(struct tcp_pcb *pcb, u8_t prio)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("tcp_setprio: invalid pcb", pcb != NULL, return);
pcb->prio = prio;
}
@ -1627,6 +1656,8 @@ tcp_seg_copy(struct tcp_seg *seg)
{
struct tcp_seg *cseg;
LWIP_ASSERT("tcp_seg_copy: invalid seg", seg != NULL);
cseg = (struct tcp_seg *)memp_malloc(MEMP_TCP_SEG);
if (cseg == NULL) {
return NULL;
@ -1646,6 +1677,9 @@ err_t
tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
LWIP_UNUSED_ARG(arg);
LWIP_ERROR("tcp_recv_null: invalid pcb", pcb != NULL, return ERR_ARG);
if (p != NULL) {
tcp_recved(pcb, p->tot_len);
pbuf_free(p);
@ -2064,7 +2098,10 @@ void
tcp_poll(struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("tcp_poll: invalid pcb", pcb != NULL, return);
LWIP_ASSERT("invalid socket state for poll", pcb->state != LISTEN);
#if LWIP_CALLBACK_API
pcb->poll = poll;
#else /* LWIP_CALLBACK_API */
@ -2082,6 +2119,8 @@ tcp_poll(struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval)
void
tcp_pcb_purge(struct tcp_pcb *pcb)
{
LWIP_ERROR("tcp_pcb_purge: invalid pcb", pcb != NULL, return);
if (pcb->state != CLOSED &&
pcb->state != TIME_WAIT &&
pcb->state != LISTEN) {
@ -2130,6 +2169,9 @@ tcp_pcb_purge(struct tcp_pcb *pcb)
void
tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
{
LWIP_ASSERT("tcp_pcb_remove: invalid pcb", pcb != NULL);
LWIP_ASSERT("tcp_pcb_remove: invalid pcblist", pcblist != NULL);
TCP_RMV(pcblist, pcb);
tcp_pcb_purge(pcb);
@ -2166,10 +2208,12 @@ u32_t
tcp_next_iss(struct tcp_pcb *pcb)
{
#ifdef LWIP_HOOK_TCP_ISN
LWIP_ASSERT("tcp_next_iss: invalid pcb", pcb != NULL);
return LWIP_HOOK_TCP_ISN(&pcb->local_ip, pcb->local_port, &pcb->remote_ip, pcb->remote_port);
#else /* LWIP_HOOK_TCP_ISN */
static u32_t iss = 6510;
LWIP_ASSERT("tcp_next_iss: invalid pcb", pcb != NULL);
LWIP_UNUSED_ARG(pcb);
iss += tcp_ticks; /* XXX */
@ -2191,6 +2235,8 @@ tcp_eff_send_mss_netif(u16_t sendmss, struct netif *outif, const ip_addr_t *dest
LWIP_UNUSED_ARG(dest); /* in case IPv6 is disabled */
LWIP_ASSERT("tcp_eff_send_mss_netif: invalid dst_ip", dest != NULL);
#if LWIP_IPV6
#if LWIP_IPV4
if (IP_IS_V6(dest))
@ -2247,6 +2293,10 @@ tcp_netif_ip_addr_changed_pcblist(const ip_addr_t *old_addr, struct tcp_pcb *pcb
{
struct tcp_pcb *pcb;
pcb = pcb_list;
LWIP_ASSERT("tcp_netif_ip_addr_changed_pcblist: invalid old_addr", old_addr != NULL);
LWIP_ASSERT("tcp_netif_ip_addr_changed_pcblist: invalid pcb_list", pcb_list != NULL);
while (pcb != NULL) {
/* PCB bound to current local interface address? */
if (ip_addr_cmp(&pcb->local_ip, old_addr)

View File

@ -128,6 +128,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
LWIP_UNUSED_ARG(inp);
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("tcp_input: invalid pbuf", p != NULL);
PERF_START;
@ -598,6 +599,8 @@ dropped:
static int
tcp_input_delayed_close(struct tcp_pcb *pcb)
{
LWIP_ASSERT("tcp_input_delayed_close: invalid pcb", pcb != NULL);
if (recv_flags & TF_CLOSED) {
/* The connection has been closed and we will deallocate the
PCB. */
@ -635,6 +638,8 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
return;
}
LWIP_ASSERT("tcp_listen_input: invalid pcb", pcb != NULL);
/* In the LISTEN state, we check for incoming SYN segments,
creates a new PCB, and responds with a SYN|ACK. */
if (flags & TCP_ACK) {
@ -741,6 +746,9 @@ tcp_timewait_input(struct tcp_pcb *pcb)
if (flags & TCP_RST) {
return;
}
LWIP_ASSERT("tcp_timewait_input: invalid pcb", pcb != NULL);
/* - fourth, check the SYN bit, */
if (flags & TCP_SYN) {
/* If an incoming segment is not acceptable, an acknowledgment
@ -785,6 +793,8 @@ tcp_process(struct tcp_pcb *pcb)
err = ERR_OK;
LWIP_ASSERT("tcp_process: invalid pcb", pcb != NULL);
/* Process incoming RST segments. */
if (flags & TCP_RST) {
/* First, determine if the reset is acceptable. */
@ -1042,6 +1052,8 @@ tcp_oos_insert_segment(struct tcp_seg *cseg, struct tcp_seg *next)
{
struct tcp_seg *old_seg;
LWIP_ASSERT("tcp_oos_insert_segment: invalid cseg", cseg != NULL);
if (TCPH_FLAGS(cseg->tcphdr) & TCP_FIN) {
/* received segment overlaps all following segments */
tcp_segs_free(next);
@ -1132,6 +1144,7 @@ tcp_receive(struct tcp_pcb *pcb)
u32_t right_wnd_edge;
int found_dupack = 0;
LWIP_ASSERT("tcp_receive: invalid pcb", pcb != NULL);
LWIP_ASSERT("tcp_receive: wrong state", pcb->state >= ESTABLISHED);
if (flags & TCP_ACK) {
@ -1901,6 +1914,8 @@ tcp_parseopt(struct tcp_pcb *pcb)
u32_t tsval;
#endif
LWIP_ASSERT("tcp_parseopt: invalid pcb", pcb != NULL);
/* Parse the TCP MSS option, if present. */
if (tcphdr_optlen != 0) {
for (tcp_optidx = 0; tcp_optidx < tcphdr_optlen; ) {

View File

@ -158,7 +158,12 @@ static struct tcp_seg *
tcp_create_segment(const struct tcp_pcb *pcb, struct pbuf *p, u8_t hdrflags, u32_t seqno, u8_t optflags)
{
struct tcp_seg *seg;
u8_t optlen = LWIP_TCP_OPT_LENGTH_SEGMENT(optflags, pcb);
u8_t optlen;
LWIP_ASSERT("tcp_create_segment: invalid pcb", pcb != NULL);
LWIP_ASSERT("tcp_create_segment: invalid pbuf", p != NULL);
optlen = LWIP_TCP_OPT_LENGTH_SEGMENT(optflags, pcb);
if ((seg = (struct tcp_seg *)memp_malloc(MEMP_TCP_SEG)) == NULL) {
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("tcp_create_segment: no memory.\n"));
@ -224,6 +229,9 @@ tcp_pbuf_prealloc(pbuf_layer layer, u16_t length, u16_t max_length,
struct pbuf *p;
u16_t alloc = length;
LWIP_ASSERT("tcp_pbuf_prealloc: invalid oversize", oversize != NULL);
LWIP_ASSERT("tcp_pbuf_prealloc: invalid pcb", pcb != NULL);
#if LWIP_NETIF_TX_SINGLE_PBUF
LWIP_UNUSED_ARG(max_length);
LWIP_UNUSED_ARG(pcb);
@ -296,6 +304,8 @@ tcp_seg_add_chksum(u16_t chksum, u16_t len, u16_t *seg_chksum,
static err_t
tcp_write_checks(struct tcp_pcb *pcb, u16_t len)
{
LWIP_ASSERT("tcp_write_checks: invalid pcb", pcb != NULL);
/* connection is in invalid state for data transmission? */
if ((pcb->state != ESTABLISHED) &&
(pcb->state != CLOSE_WAIT) &&
@ -399,8 +409,12 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags)
u16_t concat_chksummed = 0;
#endif /* TCP_CHECKSUM_ON_COPY */
err_t err;
u16_t mss_local;
LWIP_ERROR("tcp_write: invalid pcb", pcb != NULL, return ERR_ARG);
/* don't allocate segments bigger than half the maximum window we ever received */
u16_t mss_local = LWIP_MIN(pcb->mss, TCPWND_MIN16(pcb->snd_wnd_max / 2));
mss_local = LWIP_MIN(pcb->mss, TCPWND_MIN16(pcb->snd_wnd_max / 2));
mss_local = mss_local ? mss_local : pcb->mss;
LWIP_ASSERT_CORE_LOCKED();
@ -826,6 +840,8 @@ tcp_split_unsent_seg(struct tcp_pcb *pcb, u16_t split)
struct pbuf *q;
#endif /* TCP_CHECKSUM_ON_COPY */
LWIP_ASSERT("tcp_split_unsent_seg: invalid pcb", pcb != NULL);
useg = pcb->unsent;
if (useg == NULL) {
return ERR_MEM;
@ -984,6 +1000,8 @@ memerr:
err_t
tcp_send_fin(struct tcp_pcb *pcb)
{
LWIP_ASSERT("tcp_send_fin: invalid pcb", pcb != NULL);
/* first, try to add the fin to the last unsent segment */
if (pcb->unsent != NULL) {
struct tcp_seg *last_unsent;
@ -1022,6 +1040,8 @@ tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)
LWIP_ASSERT("tcp_enqueue_flags: need either TCP_SYN or TCP_FIN in flags (programmer violates API)",
(flags & (TCP_SYN | TCP_FIN)) != 0);
LWIP_ASSERT("tcp_enqueue_flags: invalid pcb", pcb != NULL);
/* No need to check pcb->snd_queuelen if only SYN or FIN are allowed! */
/* Get options for this segment. This is a special case since this is the
@ -1118,6 +1138,8 @@ tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)
static void
tcp_build_timestamp_option(const struct tcp_pcb *pcb, u32_t *opts)
{
LWIP_ASSERT("tcp_build_timestamp_option: invalid pcb", pcb != NULL);
/* Pad with two NOP options to make everything nicely aligned */
opts[0] = PP_HTONL(0x0101080A);
opts[1] = lwip_htonl(sys_now());
@ -1141,6 +1163,8 @@ tcp_get_num_sacks(const struct tcp_pcb *pcb, u8_t optlen)
{
u8_t num_sacks = 0;
LWIP_ASSERT("tcp_get_num_sacks: invalid pcb", pcb != NULL);
if (pcb->flags & TF_SACK) {
u8_t i;
@ -1170,6 +1194,9 @@ tcp_build_sack_option(const struct tcp_pcb *pcb, u32_t *opts, u8_t num_sacks)
{
u8_t i;
LWIP_ASSERT("tcp_build_sack_option: invalid pcb", pcb != NULL);
LWIP_ASSERT("tcp_build_sack_option: invalid opts", opts != NULL);
/* Pad with two NOP options to make everything nicely aligned.
We add the length (of just the SACK option, not the NOPs in front of it),
which is 2B of header, plus 8B for each SACK. */
@ -1216,6 +1243,8 @@ tcp_output(struct tcp_pcb *pcb)
#endif /* TCP_CWND_DEBUG */
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("tcp_output: invalid pcb", pcb != NULL);
/* pcb->state LISTEN not allowed here */
LWIP_ASSERT("don't call tcp_output for listen-pcbs",
pcb->state != LISTEN);
@ -1400,6 +1429,8 @@ output_done:
static int
tcp_output_segment_busy(const struct tcp_seg *seg)
{
LWIP_ASSERT("tcp_output_segment_busy: invalid seg", seg != NULL);
/* We only need to check the first pbuf here:
If a pbuf is queued for transmission, a driver calls pbuf_ref(),
which only changes the ref count of the first pbuf */
@ -1428,6 +1459,10 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif
int seg_chksum_was_swapped = 0;
#endif
LWIP_ASSERT("tcp_output_segment: invalid seg", seg != NULL);
LWIP_ASSERT("tcp_output_segment: invalid pcb", pcb != NULL);
LWIP_ASSERT("tcp_output_segment: invalid netif", netif != NULL);
if (tcp_output_segment_busy(seg)) {
/* This should not happen: rexmit functions should have checked this.
However, since this function modifies p->len, we must not continue in this case. */
@ -1595,6 +1630,8 @@ tcp_rexmit_rto_prepare(struct tcp_pcb *pcb)
{
struct tcp_seg *seg;
LWIP_ASSERT("tcp_rexmit_rto_prepare: invalid pcb", pcb != NULL);
if (pcb->unacked == NULL) {
return ERR_VAL;
}
@ -1646,6 +1683,8 @@ tcp_rexmit_rto_prepare(struct tcp_pcb *pcb)
void
tcp_rexmit_rto_commit(struct tcp_pcb *pcb)
{
LWIP_ASSERT("tcp_rexmit_rto_commit: invalid pcb", pcb != NULL);
/* increment number of retransmissions */
if (pcb->nrtx < 0xFF) {
++pcb->nrtx;
@ -1665,6 +1704,8 @@ tcp_rexmit_rto_commit(struct tcp_pcb *pcb)
void
tcp_rexmit_rto(struct tcp_pcb *pcb)
{
LWIP_ASSERT("tcp_rexmit_rto: invalid pcb", pcb != NULL);
if (tcp_rexmit_rto_prepare(pcb) == ERR_OK) {
tcp_rexmit_rto_commit(pcb);
}
@ -1683,6 +1724,8 @@ tcp_rexmit(struct tcp_pcb *pcb)
struct tcp_seg *seg;
struct tcp_seg **cur_seg;
LWIP_ASSERT("tcp_rexmit: invalid pcb", pcb != NULL);
if (pcb->unacked == NULL) {
return ERR_VAL;
}
@ -1737,6 +1780,8 @@ tcp_rexmit(struct tcp_pcb *pcb)
void
tcp_rexmit_fast(struct tcp_pcb *pcb)
{
LWIP_ASSERT("tcp_rexmit_fast: invalid pcb", pcb != NULL);
if (pcb->unacked != NULL && !(pcb->flags & TF_INFR)) {
/* This is fast retransmit. Retransmit the first unacked segment. */
LWIP_DEBUGF(TCP_FR_DEBUG,
@ -1804,7 +1849,11 @@ static struct pbuf *
tcp_output_alloc_header(struct tcp_pcb *pcb, u16_t optlen, u16_t datalen,
u32_t seqno_be /* already in network byte order */)
{
struct pbuf *p = tcp_output_alloc_header_common(pcb->rcv_nxt, optlen, datalen,
struct pbuf *p;
LWIP_ASSERT("tcp_output_alloc_header: invalid pcb", pcb != NULL);
p = tcp_output_alloc_header_common(pcb->rcv_nxt, optlen, datalen,
seqno_be, pcb->local_port, pcb->remote_port, TCP_ACK,
TCPWND_MIN16(RCV_WND_SCALE(pcb, pcb->rcv_ann_wnd)));
if (p != NULL) {
@ -1818,10 +1867,15 @@ tcp_output_alloc_header(struct tcp_pcb *pcb, u16_t optlen, u16_t datalen,
static void
tcp_output_fill_options(const struct tcp_pcb *pcb, struct pbuf *p, u8_t optflags, u8_t num_sacks)
{
struct tcp_hdr *tcphdr = (struct tcp_hdr *)p->payload;
u32_t *opts = (u32_t *)(void *)(tcphdr + 1);
struct tcp_hdr *tcphdr;
u32_t *opts;
u16_t sacks_len = 0;
LWIP_ASSERT("tcp_output_fill_options: invalid pbuf", p != NULL);
tcphdr = (struct tcp_hdr *)p->payload;
opts = (u32_t *)(void *)(tcphdr + 1);
/* NB. MSS and window scale options are only sent on SYNs, so ignore them here */
#if LWIP_TCP_TIMESTAMPS
@ -1862,7 +1916,11 @@ tcp_output_control_segment(const struct tcp_pcb *pcb, struct pbuf *p,
const ip_addr_t *src, const ip_addr_t *dst)
{
err_t err;
struct netif *netif = tcp_route(pcb, src, dst);
struct netif *netif;
LWIP_ASSERT("tcp_output_control_segment: invalid pbuf", p != NULL);
netif = tcp_route(pcb, src, dst);
if (netif == NULL) {
err = ERR_RTE;
} else {
@ -1919,7 +1977,13 @@ tcp_rst(const struct tcp_pcb *pcb, u32_t seqno, u32_t ackno,
{
struct pbuf *p;
u16_t wnd;
u8_t optlen = LWIP_TCP_OPT_LENGTH_SEGMENT(0, pcb);
u8_t optlen;
LWIP_ASSERT("tcp_rst: invalid pcb", pcb != NULL);
LWIP_ASSERT("tcp_rst: invalid local_ip", local_ip != NULL);
LWIP_ASSERT("tcp_rst: invalid remote_ip", remote_ip != NULL);
optlen = LWIP_TCP_OPT_LENGTH_SEGMENT(0, pcb);
#if LWIP_WND_SCALE
wnd = PP_HTONS(((TCP_WND >> TCP_RCV_SCALE) & 0xFFFF));
@ -1954,6 +2018,8 @@ tcp_send_empty_ack(struct tcp_pcb *pcb)
u8_t optlen, optflags = 0;
u8_t num_sacks = 0;
LWIP_ASSERT("tcp_send_empty_ack: invalid pcb", pcb != NULL);
#if LWIP_TCP_TIMESTAMPS
if (pcb->flags & TF_TIMESTAMP) {
optflags = TF_SEG_OPTS_TS;
@ -2010,6 +2076,8 @@ tcp_keepalive(struct tcp_pcb *pcb)
struct pbuf *p;
u8_t optlen = LWIP_TCP_OPT_LENGTH_SEGMENT(0, pcb);
LWIP_ASSERT("tcp_keepalive: invalid pcb", pcb != NULL);
LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: sending KEEPALIVE probe to "));
ip_addr_debug_print_val(TCP_DEBUG, pcb->remote_ip);
LWIP_DEBUGF(TCP_DEBUG, ("\n"));
@ -2051,6 +2119,8 @@ tcp_zero_window_probe(struct tcp_pcb *pcb)
u32_t snd_nxt;
u8_t optlen = LWIP_TCP_OPT_LENGTH_SEGMENT(0, pcb);
LWIP_ASSERT("tcp_zero_window_probe: invalid pcb", pcb != NULL);
LWIP_DEBUGF(TCP_DEBUG, ("tcp_zero_window_probe: sending ZERO WINDOW probe to "));
ip_addr_debug_print_val(TCP_DEBUG, pcb->remote_ip);
LWIP_DEBUGF(TCP_DEBUG, ("\n"));

View File

@ -132,6 +132,9 @@ udp_input_local_match(struct udp_pcb *pcb, struct netif *inp, u8_t broadcast)
LWIP_UNUSED_ARG(inp); /* in IPv6 only case */
LWIP_UNUSED_ARG(broadcast); /* in IPv6 only case */
LWIP_ASSERT("udp_input_local_match: invalid pcb", pcb != NULL);
LWIP_ASSERT("udp_input_local_match: invalid netif", inp != NULL);
/* check if PCB is bound to specific netif */
if ((pcb->netif_idx != NETIF_NO_INDEX) &&
(pcb->netif_idx != netif_get_index(ip_data.current_input_netif))) {
@ -198,8 +201,12 @@ udp_input(struct pbuf *p, struct netif *inp)
u8_t for_us = 0;
LWIP_UNUSED_ARG(inp);
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("udp_input: invalid pbuf", p != NULL);
LWIP_ASSERT("udp_input: invalid netif", inp != NULL);
PERF_START;
UDP_STATS_INC(udp.recv);
@ -446,7 +453,10 @@ chkerr:
err_t
udp_send(struct udp_pcb *pcb, struct pbuf *p)
{
if ((pcb == NULL) || IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) {
LWIP_ERROR("udp_send: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_ERROR("udp_send: invalid pbuf", p != NULL, return ERR_ARG);
if (IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) {
return ERR_VAL;
}
@ -462,7 +472,10 @@ err_t
udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
u8_t have_chksum, u16_t chksum)
{
if ((pcb == NULL) || IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) {
LWIP_ERROR("udp_send_chksum: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_ERROR("udp_send_chksum: invalid pbuf", p != NULL, return ERR_ARG);
if (IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) {
return ERR_VAL;
}
@ -507,7 +520,11 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
struct netif *netif;
if ((pcb == NULL) || (dst_ip == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
LWIP_ERROR("udp_sendto: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_ERROR("udp_sendto: invalid pbuf", p != NULL, return ERR_ARG);
LWIP_ERROR("udp_sendto: invalid dst_ip", dst_ip != NULL, return ERR_ARG);
if (!IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
return ERR_VAL;
}
@ -607,7 +624,12 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_i
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
const ip_addr_t *src_ip;
if ((pcb == NULL) || (dst_ip == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
LWIP_ERROR("udp_sendto_if: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_ERROR("udp_sendto_if: invalid pbuf", p != NULL, return ERR_ARG);
LWIP_ERROR("udp_sendto_if: invalid dst_ip", dst_ip != NULL, return ERR_ARG);
LWIP_ERROR("udp_sendto_if: invalid netif", netif != NULL, return ERR_ARG);
if (!IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
return ERR_VAL;
}
@ -683,7 +705,13 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d
LWIP_ASSERT_CORE_LOCKED();
if ((pcb == NULL) || (dst_ip == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) ||
LWIP_ERROR("udp_sendto_if_src: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_ERROR("udp_sendto_if_src: invalid pbuf", p != NULL, return ERR_ARG);
LWIP_ERROR("udp_sendto_if_src: invalid dst_ip", dst_ip != NULL, return ERR_ARG);
LWIP_ERROR("udp_sendto_if_src: invalid src_ip", src_ip != NULL, return ERR_ARG);
LWIP_ERROR("udp_sendto_if_src: invalid netif", netif != NULL, return ERR_ARG);
if (!IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) ||
!IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
return ERR_VAL;
}
@ -906,9 +934,8 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
#endif /* LWIP_IPV4 */
/* still need to check for ipaddr == NULL in IPv6 only case */
if ((pcb == NULL) || (ipaddr == NULL)) {
return ERR_VAL;
}
LWIP_ERROR("udp_bind: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_ERROR("udp_bind: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_TRACE, ipaddr);
@ -1033,9 +1060,8 @@ udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
LWIP_ASSERT_CORE_LOCKED();
if ((pcb == NULL) || (ipaddr == NULL)) {
return ERR_VAL;
}
LWIP_ERROR("udp_connect: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_ERROR("udp_connect: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
if (pcb->local_port == 0) {
err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
@ -1087,6 +1113,8 @@ udp_disconnect(struct udp_pcb *pcb)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("udp_disconnect: invalid pcb", pcb != NULL, return);
/* reset remote address association */
#if LWIP_IPV4 && LWIP_IPV6
if (IP_IS_ANY_TYPE_VAL(pcb->local_ip)) {
@ -1117,6 +1145,8 @@ udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("udp_recv: invalid pcb", pcb != NULL, return);
/* remember recv() callback and user data */
pcb->recv = recv;
pcb->recv_arg = recv_arg;
@ -1138,6 +1168,8 @@ udp_remove(struct udp_pcb *pcb)
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("udp_remove: invalid pcb", pcb != NULL, return);
mib2_udp_unbind(pcb);
/* pcb to be removed is first in list? */
if (udp_pcbs == pcb) {