From 60cd96905a9eab257074634a18aae8c711d62293 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 25 Sep 2022 13:05:00 +0100 Subject: [Fix] Same fix for lua_tcp --- src/lua/lua_tcp.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index 73b2c9ae2..05c9de7a2 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -1378,17 +1378,30 @@ lua_tcp_dns_handler (struct rdns_reply *reply, gpointer ud) * We set this flag as it means that we have already registered the watcher * when started DNS query */ - cbd->flags |= LUA_TCP_FLAG_RESOLVED; + struct rdns_reply_entry *entry; - if (reply->entries->type == RDNS_REQUEST_A) { - cbd->addr = rspamd_inet_address_new (AF_INET, - &reply->entries->content.a.addr); + DL_FOREACH(reply->entries, entry) { + if (entry->type == RDNS_REQUEST_A) { + cbd->addr = rspamd_inet_address_new(AF_INET, + &entry->content.a.addr); + break; + } + else if (entry->type == RDNS_REQUEST_AAAA) { + cbd->addr = rspamd_inet_address_new(AF_INET6, + &entry->content.aaa.addr); + break; + } } - else if (reply->entries->type == RDNS_REQUEST_AAAA) { - cbd->addr = rspamd_inet_address_new (AF_INET6, - &reply->entries->content.aaa.addr); + + if (cbd->addr == NULL){ + rn = rdns_request_get_name (reply->request, NULL); + lua_tcp_push_error (cbd, TRUE, "unable to resolve host: %s; no records with this name", + rn->name); + TCP_RELEASE (cbd); + return; } + cbd->flags |= LUA_TCP_FLAG_RESOLVED; rspamd_inet_address_set_port (cbd->addr, cbd->port); if (!lua_tcp_make_connection (cbd)) { -- cgit v1.2.3