@@ -5121,7 +5121,7 @@ static void rx_ip(struct mg_tcpip_if *ifp, struct pkt *pkt) {
51215121 if ((pkt->ip->ver >> 4) != 4) return; // Not IP
51225122 ihl = pkt->ip->ver & 0x0F;
51235123 if (ihl < 5) return; // bad IHL
5124- if (pkt->pay.len < (ihl * 4)) return; // Truncated / malformed
5124+ if (pkt->pay.len < (uint16_t)( ihl * 4)) return; // Truncated / malformed
51255125 // There can be link padding, take length from IP header
51265126 len = mg_ntohs(pkt->ip->len); // IP datagram length
51275127 if (len < (ihl * 4) || len > pkt->pay.len) return; // malformed
@@ -5166,7 +5166,7 @@ static void rx_ip(struct mg_tcpip_if *ifp, struct pkt *pkt) {
51665166 pkt->tcp = (struct tcp *) (pkt->pay.buf);
51675167 if (pkt->pay.len < sizeof(*pkt->tcp)) return;
51685168 off = pkt->tcp->off >> 4; // account for opts
5169- if (pkt->pay.len < (4 * off)) return;
5169+ if (pkt->pay.len < (uint16_t)( 4 * off)) return;
51705170 mkpay(pkt, (uint32_t *) pkt->tcp + off);
51715171 MG_VERBOSE(("TCP %M:%hu -> %M:%hu len %u", mg_print_ip4, &pkt->ip->src,
51725172 mg_ntohs(pkt->tcp->sport), mg_print_ip4, &pkt->ip->dst,
@@ -7811,26 +7811,19 @@ bool mg_ota_end(void) {
78117811
78127812
78137813
7814- size_t mg_queue_vprintf(struct mg_queue *q, const char *fmt, va_list *ap) {
7815- va_list ap_copy;
7816- va_copy(ap_copy, *ap);
7817- size_t len = mg_vsnprintf(NULL, 0, fmt, &ap_copy);
7818- char *buf;
7819- if (len == 0 || mg_queue_book(q, &buf, len + 1) < len + 1) {
7820- len = 0; // Nah. Not enough space
7821- } else {
7822- len = mg_vsnprintf((char *) buf, len + 1, fmt, ap);
7823- mg_queue_add(q, len);
7824- }
7825- return len;
7826- }
7827-
78287814size_t mg_queue_printf(struct mg_queue *q, const char *fmt, ...) {
7829- va_list ap ;
7815+ char *buf ;
78307816 size_t len;
7831- va_start(ap, fmt);
7832- len = mg_queue_vprintf(q, fmt, &ap);
7833- va_end(ap);
7817+ va_list ap1, ap2;
7818+ va_start(ap1, fmt);
7819+ len = mg_vsnprintf(NULL, 0, fmt, &ap1);
7820+ va_end(ap1);
7821+ if (len == 0 || mg_queue_book(q, &buf, len + 1) < len + 1)
7822+ return 0; // Nah. Not enough space
7823+ va_start(ap2, fmt);
7824+ len = mg_vsnprintf(buf, len + 1, fmt, &ap2);
7825+ mg_queue_add(q, len);
7826+ va_end(ap2);
78347827 return len;
78357828}
78367829
0 commit comments