Jinoh Kang (@iamahuman) commented about dlls/dnsapi/query.c:
if (!name || !result) return ERROR_INVALID_PARAMETER;
- if (type == DNS_TYPE_A)
- {
struct in_addr addr;
if (!RtlIpv4StringToAddressA(name, TRUE, &end, &addr) && !*end && (r = calloc(1, sizeof(*r))))
{
ret = ERROR_SUCCESS;
r->Data.A.IpAddress = addr.s_addr;
r->wDataLength = sizeof(r->Data.A);
}
The failure mode of allocation seems a bit off. When we fail to `calloc`, we have three choices of behaviors:
1. Crash. 2. Fail with error. 3. Revert to the old behavior of delegating to actual DNS query.
Here we do (3), which seems to be the most confusing choice here.[^1] Can we just drop the NULL check or handle the error properly?
(Ditto for IPv6.)
[^1]: Why? If the allocation ever fails, it will unpredictably return bogus NXDOMAIN answer to the application. If it never fails, then there is no reason for the NULL check in the first place.