casaroli opened a new pull request, #22438:
URL: https://github.com/apache/nuttx/pull/22438
## Summary
`getaddrinfo()`, `gethostbyname()` and `gethostbyaddr()` use a buffer of
`CONFIG_NETDB_BUFSIZE` bytes (default 256). The look-up puts `struct
hostent_info_s` at the start of this buffer, and the struct grows with
`CONFIG_NETDB_MAX_IPv4ADDR` and `CONFIG_NETDB_MAX_IPv6ADDR` (the hosts file
form with `CONFIG_NETDB_MAX_ALTNAMES`). With 8 IPv4 and 8 IPv6 addresses on a
64-bit target the struct has 280 bytes. Then each look-up fails with `ERANGE`,
also of a numeric address such as `"10.0.2.2"`, and `getaddrinfo()` gives
`EAI_AGAIN`. Nothing tells the user that the buffer is too small.
This PR adds a `static_assert()` that the buffer holds the struct, one IPv6
address and its text, in `lib_gethostentbynamer.c` and in
`lib_parsehostfile.c`. The Kconfig help of `NETDB_BUFSIZE` now says that the
buffer must grow with the address counts.
## Impact
A configuration with a buffer that is too small now fails to build, with a
message that names the options. Before, it built, and every look-up failed at
run time. All in-tree defconfigs build as before (the five sama5 defconfigs
with `CONFIG_NETDB_BUFSIZE=128` are 32-bit and fit). No code change, no API,
ABI or behaviour change.
## Testing
Behaviour (`qemu-armv8a:nsh` flat, IPv4 + IPv6,
`CONFIG_NETDB_MAX_IPv4ADDR=8`, `CONFIG_NETDB_MAX_IPv6ADDR=8`, default buffer of
256 bytes), a test program that resolves numeric addresses:
| | `getaddrinfo("10.0.2.2")` | `getaddrinfo("fec0::2")` |
`gethostbyname("10.0.2.2")` |
|---|---|---|---|
| master | `EAI_NONAME` | `EAI_NONAME` | NULL, `HOST_NOT_FOUND` |
| this PR | build error: `static assertion failed: "CONFIG_NETDB_BUFSIZE is
too small for CONFIG_NETDB_MAX_IPv4ADDR and CONFIG_NETDB_MAX_IPv6ADDR"` | | |
| this PR, `CONFIG_NETDB_BUFSIZE=512` | `AF_INET` | `AF_INET6` | OK |
`CONFIG_NETDB_HOSTFILE` with `CONFIG_NETDB_MAX_ALTNAMES=40`: master builds,
this PR fails with the `CONFIG_NETDB_MAX_ALTNAMES` message.
Builds with `-Werror` (CI image), all OK with no new warnings:
`qemu-armv8a:netnsh` (flat, also with IPv6 and `NETDB_HOSTFILE`),
`qemu-armv8a:knsh` with networking (kernel), `rv-virt:netnsh64` (flat; the RWX
linker warning is also on master), `rv-virt:knetnsh64` (kernel),
`jupiter-nano:sdmmc-nsh-net-resolvconf` (32-bit, `CONFIG_NETDB_BUFSIZE=128`).
checkpatch (`-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]