diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-08-28 22:44:57 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-08-28 22:44:57 +0200 |
commit | fd8a30170342cfe245ea6acac392c2b224f0ae1b (patch) | |
tree | d476a1d3cd0c5a45dc9b780cd7ee717bbfcd6ad7 /src/resolve/resolved-dns-transaction.c | |
parent | 5895a9d60079a5de5b258b282ab2262750ec51f2 (diff) | |
download | systemd-fd8a30170342cfe245ea6acac392c2b224f0ae1b.tar.gz |
resolved: make sure we initialize t->answer_errno before completing the transaction
We must have the error number around when completing the transaction.
Let's hence make sure we always initialize it *first* (we accidentally
did it once after).
Fixes: #11626
Diffstat (limited to 'src/resolve/resolved-dns-transaction.c')
-rw-r--r-- | src/resolve/resolved-dns-transaction.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index e23ea273e7..016ff0136b 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -364,6 +364,14 @@ void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state) { dns_transaction_gc(t); } +static void dns_transaction_complete_errno(DnsTransaction *t, int error) { + assert(t); + assert(error != 0); + + t->answer_errno = abs(error); + dns_transaction_complete(t, DNS_TRANSACTION_ERRNO); +} + static int dns_transaction_pick_server(DnsTransaction *t) { DnsServer *server; @@ -415,10 +423,8 @@ static void dns_transaction_retry(DnsTransaction *t, bool next_server) { dns_scope_next_dns_server(t->scope); r = dns_transaction_go(t); - if (r < 0) { - t->answer_errno = -r; - dns_transaction_complete(t, DNS_TRANSACTION_ERRNO); - } + if (r < 0) + dns_transaction_complete_errno(t, r); } static int dns_transaction_maybe_restart(DnsTransaction *t) { @@ -466,10 +472,8 @@ static void on_transaction_stream_error(DnsTransaction *t, int error) { dns_transaction_retry(t, true); return; } - if (error != 0) { - t->answer_errno = error; - dns_transaction_complete(t, DNS_TRANSACTION_ERRNO); - } + if (error != 0) + dns_transaction_complete_errno(t, error); } static int dns_transaction_on_stream_packet(DnsTransaction *t, DnsPacket *p) { @@ -836,8 +840,7 @@ static void dns_transaction_process_dnssec(DnsTransaction *t) { return; fail: - t->answer_errno = -r; - dns_transaction_complete(t, DNS_TRANSACTION_ERRNO); + dns_transaction_complete_errno(t, r); } static int dns_transaction_has_positive_answer(DnsTransaction *t, DnsAnswerFlags *flags) { @@ -1169,8 +1172,7 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p) { return; fail: - t->answer_errno = -r; - dns_transaction_complete(t, DNS_TRANSACTION_ERRNO); + dns_transaction_complete_errno(t, r); } static int on_dns_packet(sd_event_source *s, int fd, uint32_t revents, void *userdata) { @@ -1196,8 +1198,7 @@ static int on_dns_packet(sd_event_source *s, int fd, uint32_t revents, void *use return 0; } if (r < 0) { - dns_transaction_complete(t, DNS_TRANSACTION_ERRNO); - t->answer_errno = -r; + dns_transaction_complete_errno(t, r); return 0; } if (r == 0) |