https://bugs.freebsd.org/237778
The magical "sysctl.name" (0.1), gets the 'string name' from the 'int id' of a node, It returns 0 (false positive) and builds a fake name for a non-existent OID. The problem is reproducible by the attached file 'bad_name.c' PR237778 comment 1 (or bad_name.c).
We use 'sysctl.name' sysctl_sysctl_name() with '/sbin/sysctl -a' and '/sbin/sysctl -aN' (always positive case: existing node), I found it while I was writing a "sysctl library" then I should consider also the negative case (the others internal/magical OIDs sysctl.{oiddesc|oidfmt|oidlabel} return an error for a non-existent node).
Implementation note (https://gitlab.com/alfix/kernel-sysctlmibinfo/tree/master/bad_name_testing)
sysctl.{oiddesc|oidfmt|oidlabel} call sysctl_find_oid() to search the node and check the DORMANT and/or DYING flags, then my first patch 'patch_1' was just a call to sysctl_find_oid() and sysctl_search_oid() to build the path and the name. Unfortunately this elegant implementation is not efficient (2 visits of the tree, patch_1/time_*. txt).
The final solution is "merging" sysctl_find_oid() and sysctl_search_oid(): patch_2/kern_sysctl.c, test plan below.