From 99e1f37b8238a9f5956e3394ed982c6d4d050c82 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Thu, 20 Jul 2017 12:00:57 -0500 Subject: [PATCH] IP_PKTINFO: set msg_controllen upon output This fixes a bug where when writing IP_PKTINFO to msg_control, the msg_controllen field was not updated with the length written This bug is exposed by applications that provide a msg_control buffer large enough for multiple control messages. Then when calling CMSG_NXTHDR, it returned a next cmsg pointer even though was no additional message --- src/api/sockets.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/sockets.c b/src/api/sockets.c index 4d67d274..bbbf3916 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -1088,6 +1088,7 @@ lwip_recvfrom_udp_raw(struct lwip_sock *sock, int flags, struct msghdr *msg, u16 chdr->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo)); pkti->ipi_ifindex = buf->p->if_idx; inet_addr_from_ip4addr(&pkti->ipi_addr, ip_2_ip4(netbuf_destaddr(buf))); + msg->msg_controllen = CMSG_SPACE(sizeof(struct in_pktinfo)); wrote_msg = 1; } else { msg->msg_flags |= MSG_CTRUNC;