This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a4364bbb45fffeec674c2bddde790f40310fddb1 Author: gaohedong <[email protected]> AuthorDate: Tue Oct 13 16:14:43 2026 +0800 net/udp: initialize readahead meta variables in udp_readahead. Coverity CID 3934125 / 3934127 (MISRA C-2012 Rule 9.1): src_addr_size and srcaddr are read before being explicitly initialized. CID 3934125 points at the iob_copyout() call that uses src_addr_size as the copy length, CID 3934127 at the memcpy() that copies srcaddr into msg_name. Both are filled in by an earlier iob_copyout(), but iob_copyout() has two early returns (-ESPIPE on a bad offset, 0 when the iob chain is exhausted) that write nothing, so Rule 9.1 is violated on those paths. In practice those paths are unreachable here: udp_callback() writes the whole |datalen|ifindex|src_addr_size|src_addr| header into one iob with consecutive iob_trycopyin() calls and drops the packet entirely if any of them fails, so the reader always finds a complete fixed-size header. The DEBUGASSERT() checks that follow cannot stand in for initialization either - they run after the read and compile to nothing when CONFIG_DEBUG_ASSERTIONS is disabled. This change is therefore a static-compliance fix with no runtime behaviour change. Note the earlier attempt (change 7995723) initialized only srcaddr and left src_addr_size untouched, which is why CID 3934125 kept recurring. Signed-off-by: gaohedong <[email protected]> --- net/udp/udp_recvfrom.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/udp/udp_recvfrom.c b/net/udp/udp_recvfrom.c index 822907f954e..8cbf97233b8 100644 --- a/net/udp/udp_recvfrom.c +++ b/net/udp/udp_recvfrom.c @@ -164,7 +164,7 @@ static inline void udp_readahead(struct udp_recvfrom_s *pstate) int offset = 0; int pos; uint16_t datalen = 0; - uint8_t src_addr_size; + uint8_t src_addr_size = 0; uint8_t ifindex; uint8_t meta[UDP_READAHEAD_META_SIZE]; #ifdef CONFIG_NET_IPv6 @@ -173,6 +173,8 @@ static inline void udp_readahead(struct udp_recvfrom_s *pstate) uint8_t srcaddr[sizeof(struct sockaddr_in)]; #endif + memset(srcaddr, 0, sizeof(srcaddr)); + /* Unflatten saved connection information * Layout: |datalen|ifindex|src_addr_size|src_addr|[timestamp]|data| */
