return EAI_ADDRFAMILY instead of NULL (propagate to caller)

Signed-off-by: Kirill Rodriguez <theoden8@gmail.com>
This commit is contained in:
Kirill Rodriguez 2024-11-02 00:53:31 +00:00
parent 7d0836c2b8
commit e219dd4a6e
No known key found for this signature in database
GPG Key ID: 2AA85EC2AD7F85EA
3 changed files with 15 additions and 9 deletions

17
evdns.c
View File

@ -5440,8 +5440,9 @@ evdns_cache_lookup(struct evdns_base *base,
EVDNS_UNLOCK(base); EVDNS_UNLOCK(base);
out: out:
if (n_found) { if (n_found) {
/* Note that we return an empty answer if we found entries for if (!ai) {
* this hostname but none were of the right address type. */ return EVUTIL_EAI_ADDRFAMILY;
}
*res = ai; *res = ai;
return 0; return 0;
} else { } else {
@ -5764,16 +5765,20 @@ evdns_getaddrinfo(struct evdns_base *dns_base,
} }
/* If there is an entry in the hosts file, we should give it now. */ /* If there is an entry in the hosts file, we should give it now. */
if (!evdns_getaddrinfo_fromhosts(dns_base, nodename, &hints, port, &res)) { err = evdns_getaddrinfo_fromhosts(dns_base, nodename, &hints, port, &res);
cb(0, res, arg); if (!err || err == EVUTIL_EAI_ADDRFAMILY) {
cb(err, res, arg);
return NULL; return NULL;
} }
/* See if we have it in the cache */ /* See if we have it in the cache */
if (!dns_base->disable_cache && !evdns_cache_lookup(dns_base, nodename, &hints, port, &res)) { if (!dns_base->disable_cache) {
cb(0, res, arg); err = evdns_cache_lookup(dns_base, nodename, &hints, port, &res);
if (!err || err == EVUTIL_EAI_ADDRFAMILY) {
cb(err, res, arg);
return NULL; return NULL;
} }
}
/* Okay, things are serious now. We're going to need to actually /* Okay, things are serious now. We're going to need to actually
* launch a request. * launch a request.

View File

@ -819,6 +819,7 @@ struct evdns_getaddrinfo_request;
* - For ai_protocol, we only handle IPPROTO_TCP, IPPROTO_UDP, and 0. * - For ai_protocol, we only handle IPPROTO_TCP, IPPROTO_UDP, and 0.
* - If we cached a response exclusively for a different address type (e.g. * - If we cached a response exclusively for a different address type (e.g.
* PF_INET), we will set addrinfo to NULL (e.g. queried with PF_INET6) * PF_INET), we will set addrinfo to NULL (e.g. queried with PF_INET6)
* and return EVUTIL_EAI_ADDRFAMILY.
* - Cache isn't hit when AI_CANONNAME is set but cached server response * - Cache isn't hit when AI_CANONNAME is set but cached server response
* doesn't contain CNAME. * doesn't contain CNAME.
* - If we can answer immediately (e.g. using hosts file, there is an error * - If we can answer immediately (e.g. using hosts file, there is an error

View File

@ -2155,7 +2155,7 @@ test_getaddrinfo_async(void *arg)
tt_assert(!b_out[2].ai->ai_next); tt_assert(!b_out[2].ai->ai_next);
test_ai_eq(b_out[2].ai, "[b0b::f00d]:8002", SOCK_STREAM, IPPROTO_TCP); test_ai_eq(b_out[2].ai, "[b0b::f00d]:8002", SOCK_STREAM, IPPROTO_TCP);
/* 2.5: v6only.example.com cache lookup with PF_INET should return NULL addressinfo. */ /* 2.5: v6only.example.com cache lookup with PF_INET should return EVUTIL_EAI_ADDRFAMILY. */
hints.ai_family = PF_INET; hints.ai_family = PF_INET;
hints.ai_flags = 0; hints.ai_flags = 0;
evutil_freeaddrinfo(b_out[2].ai); // since this is reused evutil_freeaddrinfo(b_out[2].ai); // since this is reused
@ -2164,7 +2164,7 @@ test_getaddrinfo_async(void *arg)
&hints, gai_cb, &b_out[2]); &hints, gai_cb, &b_out[2]);
tt_assert(!r); tt_assert(!r);
// check // check
tt_int_op(b_out[2].err, ==, 0); tt_int_op(b_out[2].err, ==, EVUTIL_EAI_ADDRFAMILY);
tt_assert(!b_out[2].ai); tt_assert(!b_out[2].ai);
/* 3: v4assert.example.com should have been cached */ /* 3: v4assert.example.com should have been cached */