]> git.ipfire.org Git - thirdparty/bind9.git/commit
Process dig -x reverse octets iteratively
authorOndřej Surý <ondrej@isc.org>
Thu, 30 Apr 2026 09:31:51 +0000 (11:31 +0200)
committerOndřej Surý <ondrej@isc.org>
Thu, 30 Apr 2026 12:02:02 +0000 (14:02 +0200)
commitf1ec5e18098cd13e9e6b3a1a6579ff2ff5ab5e1c
tree8f8dc61ff96fcfb3d62a22ff0afecb7256165a8e
parent688e8667a32b94a195df51501ffff1b7e32c1b68
Process dig -x reverse octets iteratively

reverse_octets() recursed once per dot, with depth bounded only by
ARG_MAX (~2 MiB on Linux), so feeding dig -x a deep input like
'1.1.1.…1' busted the call stack and crashed the tool with SIGSEGV
instead of a structured error.  The transformation it performs is
purely textual (split on '.', emit components in reverse), so the
recursion was never load-bearing.

Walk the input once into a fixed-size array of label slices, capped at
DNS_NAME_MAXLABELS (which is the most we could ever fit into the
result buffer anyway), then iterate the array in reverse to write the
output.  Inputs with more than DNS_NAME_MAXLABELS labels now return
DNS_R_NAMETOOLONG, which dig.c surfaces as 'Invalid IP address' and
exit 1.  Drop the unnecessary (int) casts on ptrdiff_t/size_t lengths
while at it.

Assisted-by: Claude:claude-opus-4-7
bin/dig/dighost.c
bin/tests/system/digdelv/tests.sh