zhhyu7 opened a new pull request, #21820: URL: https://github.com/apache/nuttx/pull/21820
*Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary A batch of independent net/udp fixes, one diagnostic helper and two Coverity/MISRA clean-ups: - **Add Ethernet header to loopback message** — loopback packets leaving the Ethernet device have no L2 header, but ipv4/ipv6_in subtract the LL header length, so the packets were dropped on a length mismatch. - **Modify the return type of udp_recvfrom_newdata** — change recvlen from size_t to ssize_t and drop the unused return value. - **fix udp_find_conn to check both local addresses for overlap** — bind conflict detection only checked the existing conn for INADDR_ANY, not the new binding, so `bind(10.0.2.15:7400)` then `bind(0.0.0.0:7400)` wrongly succeeded. Make the wildcard overlap check symmetric (Linux-consistent). - **free callback in cleanup when pthread is canceled** — when a pthread is canceled during udp_recvfrom(), the cleanup handler destroyed the sem but left the devif callback registered; a later datagram then posted a destroyed sem (use-after-free). Free the callback before destroying it, mirroring tcp_callback_cleanup(). - **serialize NETDEV_DOWN write_q release** — NETDEV_DOWN reaches sendto_eventhandler without conn_lock, racing with psock_udp_sendto's write_q walk (KASAN UAF). Take conn_lock once conn is recovered. - **resolve local address in udp_path for fdinfo display** — a connected UDP socket with no prior bind() showed 0.0.0.0 in fdinfo; resolve the real local IP for display only, without changing conn state. - **initialize datalen (x2)** — zero-init datalen in udp_ioctl.c and udp_recvfrom.c to satisfy Coverity / MISRA C-2012 Rule 9.1 (no behavioral change; iob_copyout writes it before use). - **add debug logging for error and warning paths** — nerr/nwarn on the UDP error paths (auto-bind exhaustion, port conflict, alloc failures, size limit, missing destination, write-buffer prep failure). ## Impact No API or configuration change. Three are bug fixes (bind overlap, recvfrom-cancel UAF, NETDEV_DOWN write_q UAF), the rest are a dropped-packet fix on Ethernet loopback, an fdinfo display fix, a type cleanup, two Coverity/MISRA initializers and added diagnostics. ## Testing Built and run on the simulator (flat build). Build: - `./tools/configure.sh sim:dynconns` (TCP, UDP, ICMP, ICMPv6, PKT, LOCAL, NETLINK) — `make` completes, nuttx links. - `./tools/checkpatch.sh -c -m -g HEAD~9..HEAD` — passes for all 9 commits. Runtime (sim + NET_UDP + NET_LOOPBACK): nsh> udploop udploop: received 'udp-loopback-hello' (18 bytes) from 127.0.0.1:11368 udploop: UDP loopback PASS -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
