Skip to content

Commit

Permalink
resolved: fix use of ERRNO_IS_DISCONNECT()
Browse files Browse the repository at this point in the history
Given that ERRNO_IS_DISCONNECT() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the argument passed to ERRNO_IS_DISCONNECT() is the value
returned by manager_recv() which can legitimately return 1 without errno
semantics, so fix this by moving ERRNO_IS_DISCONNECT() invocation to the
branch where the return value is known to be negative.
  • Loading branch information
ldv-alt committed Jul 16, 2023
1 parent bb228f0 commit 0bdea17
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/resolve/resolved-dns-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,25 +1367,22 @@ static int on_dns_packet(sd_event_source *s, int fd, uint32_t revents, void *use
assert(t->scope);

r = manager_recv(t->scope->manager, fd, DNS_PROTOCOL_DNS, &p);
if (ERRNO_IS_DISCONNECT(r)) {
usec_t usec;

/* UDP connection failures get reported via ICMP and then are possibly delivered to us on the
* next recvmsg(). Treat this like a lost packet. */
if (r < 0) {
if (ERRNO_IS_DISCONNECT(r)) {
usec_t usec;

log_debug_errno(r, "Connection failure for DNS UDP packet: %m");
assert_se(sd_event_now(t->scope->manager->event, CLOCK_BOOTTIME, &usec) >= 0);
dns_server_packet_lost(t->server, IPPROTO_UDP, t->current_feature_level);
/* UDP connection failures get reported via ICMP and then are possibly delivered to us on the
* next recvmsg(). Treat this like a lost packet. */

dns_transaction_close_connection(t, /* use_graveyard = */ false);
log_debug_errno(r, "Connection failure for DNS UDP packet: %m");
assert_se(sd_event_now(t->scope->manager->event, CLOCK_BOOTTIME, &usec) >= 0);
dns_server_packet_lost(t->server, IPPROTO_UDP, t->current_feature_level);

if (dns_transaction_limited_retry(t)) /* Try a different server */
return 0;
dns_transaction_close_connection(t, /* use_graveyard = */ false);

dns_transaction_complete_errno(t, r);
return 0;
}
if (r < 0) {
if (dns_transaction_limited_retry(t)) /* Try a different server */
return 0;
}
dns_transaction_complete_errno(t, r);
return 0;
}
Expand Down

0 comments on commit 0bdea17

Please sign in to comment.