diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 0a0c9ea2..0a768448 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -1315,6 +1315,7 @@ do_dns_found(const char *name, struct ip_addr *ipaddr, void *arg) struct dns_api_msg *msg = (struct dns_api_msg*)arg; LWIP_ASSERT("DNS response for wrong host name", strcmp(msg->name, name) == 0); + LWIP_UNUSED_ARG(name); if (ipaddr == NULL) { /* timeout or memory error */ diff --git a/src/api/netdb.c b/src/api/netdb.c index 69a331be..88135a55 100644 --- a/src/api/netdb.c +++ b/src/api/netdb.c @@ -315,7 +315,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname, sa->sin_addr.s_addr = addr.addr; sa->sin_family = AF_INET; sa->sin_len = sizeof(struct sockaddr_in); - sa->sin_port = htons(port_nr); + sa->sin_port = htons((u16_t)port_nr); /* set up addrinfo */ ai->ai_family = AF_INET; diff --git a/src/api/sockets.c b/src/api/sockets.c index 32c3752b..2ff41de0 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -318,7 +318,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen) * In that case, newconn->socket is counted down (newconn->socket--), * so nsock->rcvevent is >= 1 here! */ - nsock->rcvevent += -1 - newconn->socket; + nsock->rcvevent += (s16_t)(-1 - newconn->socket); newconn->socket = newsock; sys_sem_signal(socksem); @@ -455,14 +455,9 @@ lwip_listen(int s, int backlog) return -1; /* limit the "backlog" parameter to fit in an u8_t */ - if (backlog < 0) { - backlog = 0; - } - if (backlog > 0xff) { - backlog = 0xff; - } + backlog = LWIP_MIN(LWIP_MAX(backlog, 0), 0xff); - err = netconn_listen_with_backlog(sock->conn, backlog); + err = netconn_listen_with_backlog(sock->conn, (u8_t)backlog); if (err != ERR_OK) { LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d) failed, err=%d\n", s, err)); @@ -1557,7 +1552,7 @@ int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) { struct lwip_socket *sock = get_socket(s); - int err = ERR_OK; + err_t err = ERR_OK; struct lwip_setgetsockopt_data data; if (!sock) @@ -1901,21 +1896,21 @@ lwip_setsockopt_internal(void *arg) case IPPROTO_UDPLITE: switch (optname) { case UDPLITE_SEND_CSCOV: - if ((*(int*)optval != 0) && (*(int*)optval < 8)) { + if ((*(int*)optval != 0) && ((*(int*)optval < 8)) || (*(int*)optval > 0xffff)) { /* don't allow illegal values! */ sock->conn->pcb.udp->chksum_len_tx = 8; } else { - sock->conn->pcb.udp->chksum_len_tx = *(int*)optval; + sock->conn->pcb.udp->chksum_len_tx = (u16_t)*(int*)optval; } LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_UDPLITE, UDPLITE_SEND_CSCOV) -> %d\n", s, (*(int*)optval)) ); break; case UDPLITE_RECV_CSCOV: - if ((*(int*)optval != 0) && (*(int*)optval < 8)) { + if ((*(int*)optval != 0) && ((*(int*)optval < 8)) || (*(int*)optval > 0xffff)) { /* don't allow illegal values! */ sock->conn->pcb.udp->chksum_len_rx = 8; } else { - sock->conn->pcb.udp->chksum_len_rx = *(int*)optval; + sock->conn->pcb.udp->chksum_len_rx = (u16_t)*(int*)optval; } LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_UDPLITE, UDPLITE_RECV_CSCOV) -> %d\n", s, (*(int*)optval)) ); diff --git a/src/core/dhcp.c b/src/core/dhcp.c index 82068bfd..1f93d2fd 100644 --- a/src/core/dhcp.c +++ b/src/core/dhcp.c @@ -282,7 +282,9 @@ dhcp_select(struct netif *netif) #if LWIP_NETIF_HOSTNAME p = (const char*)netif->hostname; if (p != NULL) { - dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, strlen(p)); + u8_t namelen = (u8_t)strlen(p); + LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255); + dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen); while (*p) { dhcp_option_byte(dhcp, *p++); } @@ -990,7 +992,9 @@ dhcp_renew(struct netif *netif) #if LWIP_NETIF_HOSTNAME p = (const char*)netif->hostname; if (p != NULL) { - dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, strlen(p)); + u8_t namelen = (u8_t)strlen(p); + LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255); + dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen); while (*p) { dhcp_option_byte(dhcp, *p++); } @@ -1056,7 +1060,9 @@ dhcp_rebind(struct netif *netif) #if LWIP_NETIF_HOSTNAME p = (const char*)netif->hostname; if (p != NULL) { - dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, strlen(p)); + u8_t namelen = (u8_t)strlen(p); + LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255); + dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen); while (*p) { dhcp_option_byte(dhcp, *p++); } diff --git a/src/core/dns.c b/src/core/dns.c index cb3d0a68..ac22e953 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -625,7 +625,7 @@ dns_send(u8_t numdns, const char* name, u8_t id) MEMCPY( query, &qry, SIZEOF_DNS_QUERY); /* resize pbuf to the exact dns query */ - pbuf_realloc(p, (query + SIZEOF_DNS_QUERY) - ((char*)(p->payload))); + pbuf_realloc(p, (u16_t)((query + SIZEOF_DNS_QUERY) - ((char*)(p->payload)))); /* connect to the server for faster receiving */ udp_connect(dns_pcb, &dns_servers[numdns], DNS_SERVER_PORT); @@ -741,12 +741,12 @@ dns_check_entries(void) static void dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port) { - u8_t i; + u16_t i; char *pHostname; struct dns_hdr *hdr; struct dns_answer ans; struct dns_table_entry *pEntry; - u8_t nquestions, nanswers; + u16_t nquestions, nanswers; #if (DNS_USES_STATIC_BUF == 0) u8_t dns_payload[DNS_MSG_SIZE]; #endif /* (DNS_USES_STATIC_BUF == 0) */ diff --git a/src/core/ipv4/inet_chksum.c b/src/core/ipv4/inet_chksum.c index 185881ef..d7401229 100644 --- a/src/core/ipv4/inet_chksum.c +++ b/src/core/ipv4/inet_chksum.c @@ -181,7 +181,7 @@ lwip_standard_chksum(void *dataptr, int len) sum = SWAP_BYTES_IN_WORD(sum); } - return sum; + return (u16_t)sum; } #endif @@ -263,7 +263,7 @@ lwip_standard_chksum(void *dataptr, int len) sum = SWAP_BYTES_IN_WORD(sum); } - return sum; + return (u16_t)sum; } #endif diff --git a/src/core/ipv4/ip_frag.c b/src/core/ipv4/ip_frag.c index 1939d831..852d0b9b 100644 --- a/src/core/ipv4/ip_frag.c +++ b/src/core/ipv4/ip_frag.c @@ -155,7 +155,8 @@ ip_reass_tmr(void) static int ip_reass_free_complete_datagram(struct ip_reassdata *ipr, struct ip_reassdata *prev) { - int pbufs_freed = 0; + u16_t pbufs_freed = 0; + u8_t clen; struct pbuf *p; struct ip_reass_helper *iprh; @@ -175,7 +176,9 @@ ip_reass_free_complete_datagram(struct ip_reassdata *ipr, struct ip_reassdata *p /* Then, copy the original header into it. */ SMEMCPY(p->payload, &ipr->iphdr, IP_HLEN); icmp_time_exceeded(p, ICMP_TE_FRAG); - pbufs_freed += pbuf_clen(p); + clen = pbuf_clen(p); + LWIP_ASSERT("pbufs_freed + clen <= 0xffff", pbufs_freed + clen <= 0xffff); + pbufs_freed += clen; pbuf_free(p); } #endif /* LWIP_ICMP */ @@ -189,8 +192,10 @@ ip_reass_free_complete_datagram(struct ip_reassdata *ipr, struct ip_reassdata *p pcur = p; /* get the next pointer before freeing */ p = iprh->next_pbuf; - pbufs_freed += pbuf_clen(pcur); - pbuf_free(pcur); + clen = pbuf_clen(pcur); + LWIP_ASSERT("pbufs_freed + clen <= 0xffff", pbufs_freed + clen <= 0xffff); + pbufs_freed += clen; + pbuf_free(pcur); } /* Then, unchain the struct ip_reassdata from the list and free it. */ ip_reass_dequeue_datagram(ipr, prev); diff --git a/src/core/snmp/msg_out.c b/src/core/snmp/msg_out.c index b705aaca..c0557d70 100644 --- a/src/core/snmp/msg_out.c +++ b/src/core/snmp/msg_out.c @@ -234,10 +234,10 @@ snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap) /* lookup current source address for this dst */ dst_if = ip_route(&td->dip); dst_ip.addr = ntohl(dst_if->ip_addr.addr); - trap_msg.sip_raw[0] = dst_ip.addr >> 24; - trap_msg.sip_raw[1] = dst_ip.addr >> 16; - trap_msg.sip_raw[2] = dst_ip.addr >> 8; - trap_msg.sip_raw[3] = dst_ip.addr; + trap_msg.sip_raw[0] = (u8_t)(dst_ip.addr >> 24); + trap_msg.sip_raw[1] = (u8_t)(dst_ip.addr >> 16); + trap_msg.sip_raw[2] = (u8_t)(dst_ip.addr >> 8); + trap_msg.sip_raw[3] = (u8_t)dst_ip.addr; trap_msg.gen_trap = generic_trap; trap_msg.spc_trap = specific_trap; if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC) diff --git a/src/core/tcp.c b/src/core/tcp.c index a39857cf..a06a9864 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -422,7 +422,9 @@ u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb) pcb->rcv_ann_wnd = 0; } else { /* keep the right edge of window constant */ - pcb->rcv_ann_wnd = pcb->rcv_ann_right_edge - pcb->rcv_nxt; + u32_t new_rcv_ann_wnd = pcb->rcv_ann_right_edge - pcb->rcv_nxt; + LWIP_ASSERT("new_rcv_ann_wnd <= 0xffff", new_rcv_ann_wnd <= 0xffff); + pcb->rcv_ann_wnd = (u16_t)new_rcv_ann_wnd; } return 0; } diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index ddada420..726d4d60 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -60,7 +60,7 @@ static void tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb); static struct tcp_hdr * -tcp_output_set_header(struct tcp_pcb *pcb, struct pbuf *p, int optlen, +tcp_output_set_header(struct tcp_pcb *pcb, struct pbuf *p, u16_t optlen, u32_t seqno_be /* already in network byte order */) { struct tcp_hdr *tcphdr = p->payload; diff --git a/test/unit/tcp/tcp_helper.c b/test/unit/tcp/tcp_helper.c index 98ee5eb6..092cdd19 100644 --- a/test/unit/tcp/tcp_helper.c +++ b/test/unit/tcp/tcp_helper.c @@ -57,7 +57,7 @@ tcp_create_segment(struct ip_addr* src_ip, struct ip_addr* dst_ip, struct pbuf* p; struct ip_hdr* iphdr; struct tcp_hdr* tcphdr; - u16_t pbuf_len = sizeof(struct ip_hdr) + sizeof(struct tcp_hdr) + data_len; + u16_t pbuf_len = (u16_t)(sizeof(struct ip_hdr) + sizeof(struct tcp_hdr) + data_len); p = pbuf_alloc(PBUF_RAW, pbuf_len, PBUF_POOL); EXPECT_RETNULL(p != NULL); @@ -82,7 +82,7 @@ tcp_create_segment(struct ip_addr* src_ip, struct ip_addr* dst_ip, tcphdr->ackno = htonl(ackno); TCPH_HDRLEN_SET(tcphdr, sizeof(struct tcp_hdr)/4); TCPH_FLAGS_SET(tcphdr, headerflags); - tcphdr->wnd = htonl(TCP_WND); + tcphdr->wnd = htons(TCP_WND); /* copy data */ memcpy((char*)tcphdr + sizeof(struct tcp_hdr), data, data_len);