casaroli opened a new pull request, #21534: URL: https://github.com/apache/nuttx/pull/21534
## Summary `recvfrom()` of a local datagram socket set the address length to the length of the name without the family, so it was two bytes short. A kernel build copies only that length back to the program, so the program lost the last two bytes of the sender's name, and a server could not answer its client (`/tmp/dgramfrom-5-s` came back as `/tmp/dgramfrom-5`). Also, the name and its NUL could go two bytes past the buffer of the caller, because the limit did not count the family. This PR counts the family and the NUL in both places. The address of an unbound sender has the family only. ## Impact Local datagram sockets only, the same code in flat, protected and kernel builds; no architecture code. The returned address length of a bound sender grows by 3 bytes (the family and the NUL), and that of an unbound sender is 2 instead of 0, as `recvfrom()` describes it: the size of the address stored. A program that used the old length as the length of the name only must change; a program that gives the address back to `sendto()` now works in a kernel build. This changes a value that a flat-build function returns. No Documentation change: `Documentation/reference/user/11_network.rst` already describes `fromlen` this way. ## Testing Test program `dgramfrom.c`, pathnames only, each address with its NUL inside `addrlen`: `named` (the sender is bound: `recvfrom()` gives its whole name, and the length `offsetof(struct sockaddr_un, sun_path) + strlen(name) + 1`), `unnamed` (an unbound sender: the length `sizeof(sa_family_t)`, as on Linux), `short` (a buffer of 6 bytes: nothing is written past it). Also `dgramabs.c` `recvname`. The tests are not in apps; a regression guard would need an apps PR. | qemu-armv8a, HVF | master 43f7f34b995 | this branch | |---|---|---| | `dgramfrom` on `knsh` (kernel) | `named` FAIL: `/tmp/dgramfrom-5` for `/tmp/dgramfrom-5-s`, length 18 (21 expected); `unnamed` FAIL: length 0; `short` PASS | 3 PASS | | `dgramfrom` on `nsh` (flat), builtin application | `named` FAIL: length 18; `short` FAIL: 2 bytes written past the buffer; `unnamed` FAIL: length 0 | 3 PASS | | `dgramabs` `recvname` on `nsh` (flat) | FAIL: length 21 for a 21-byte name | PASS | | ostest on knsh, nsh, and the flat build with the tests | status 0 | status 0 | On `knsh`, `dgramabs` `recvname` fails on master and on this branch for another reason: its `sendto()` to an abstract name fails with `ENOENT`, as `sendto()` reads the name past `addrlen` (a separate fix). The other `dgramabs` cases are the same on master and on this branch. Options: `NET`, `NET_LOCAL`, `NET_LOCAL_STREAM`, `NET_LOCAL_DGRAM`, `NETDEV_LATEINIT`, `NET_SOCKOPTS`, `PIPES`. Builds with `EXTRAFLAGS="-Wno-cpp -Werror"` and the network options, each OK with no warning: `rv-virt:knsh64` (kernel), `mps2-an500:knsh` (protected). Compilers: aarch64 GCC 14.2, riscv-none-elf GCC 14.3, arm-none-eabi GCC 15.3. Not run: buffer sizes other than 6 bytes and the full structure. `tools/checkpatch.sh -c -u -m -g` passes. -- 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]
