nuttx/libs/libc/netdb
Justin Hammond cda33ae4fc libs/libc/netdb: Size an answer header by its header, not by its union.
dns_recv_response() checked for room using sizeof(struct dns_answer_s),
but that structure is the 10-byte header plus a union holding the largest
address it can carry.  With IPv6 built the union is 16 bytes, so the check
demanded 26 bytes where 10 were needed, and any answer sitting at the end
of a response was rejected as truncated.

An A record answer supplies 14 bytes, so whether a lookup worked depended
on how much padding the server happened to send after it:

  $ dig +noedns @10.1.1.2 github.com A      # ANSWER 1, AUTHORITY 0, ADDITIONAL 0
  -> answer is last in the packet, 14 bytes remain, rejected

  $ dig +noedns @10.11.5.254 github.com A   # ANSWER 1, AUTHORITY 13, ADDITIONAL 7
  -> 26+ bytes remain, accepted

On the board, before and after, against the first of those servers:

  nsh> nslookup apache.org
  [CPU1] dns_recv_response: DNS answer header truncated
  Host: apache.org Addr: 2a04:4e42::644                 <- A record lost

  nsh> nslookup apache.org
  Host: apache.org Addr: 2a04:4e42::644
  Host: apache.org Addr: 151.101.2.132                  <- both returned

The address that follows the header is already bounds checked separately,
where its real length is known, so only the header check was wrong.  The
size is now a named constant next to the structure, since the rest of this
function already used the literal 10 for the same quantity.

Only IPv4-only builds escaped it, where sizeof happens to equal 14 and an
A record fits exactly.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Justin Hammond <justin@dynam.ac>
2026-08-08 15:02:15 -03:00
..
CMakeLists.txt netdb/lib_dnsdelserver.c: support delete the DNS server address 2025-11-08 16:17:40 -03:00
Kconfig libs/libc/netdb: Optimize the timeout calculation logic: 2025-08-06 01:58:05 +08:00
lib_dn.c
lib_dns.h libs/libc/netdb: Optimize the timeout calculation logic: 2025-08-06 01:58:05 +08:00
lib_dnsaddserver.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
lib_dnsbind.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
lib_dnscache.c !sys/types.h: change time_t and clock_t to int64_t to align with other OSes 2026-05-19 16:21:28 +08:00
lib_dnsdefaultserver.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
lib_dnsdelserver.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
lib_dnsforeach.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
lib_dnsinit.c
lib_dnsnotify.c libs: unify Private Types banners 2025-05-28 10:17:15 +08:00
lib_dnsquery.c libs/libc/netdb: Size an answer header by its header, not by its union. 2026-08-08 15:02:15 -03:00
lib_dnsqueryfamily.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
lib_freeaddrinfo.c
lib_gaistrerror.c
lib_getaddrinfo.c style/FAR: remove FAR qualifier 2025-11-10 10:56:29 +01:00
lib_gethostbyaddr.c
lib_gethostbyaddrr.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
lib_gethostbyname.c
lib_gethostbyname2.c
lib_gethostbyname2r.c
lib_gethostbynamer.c
lib_gethostentbynamer.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
lib_getnameinfo.c
lib_getservbyname.c
lib_getservbynamer.c netdb: Add http and https service entries 2026-07-23 15:34:02 +08:00
lib_getservbyport.c
lib_getservbyportr.c
lib_netdb.c
lib_netdb.h
lib_parsehostfile.c style/FAR: remove FAR qualifier 2025-11-10 10:56:29 +01:00
lib_proto.c
lib_protor.c
lib_rexec.c style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
Make.defs netdb/lib_dnsdelserver.c: support delete the DNS server address 2025-11-08 16:17:40 -03:00