diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-09-25 13:02:22 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-09-25 13:02:22 +0100 |
commit | 89252bcf03a2213a72f348e210240bb96848e5aa (patch) | |
tree | 2293f0c4f4920a5bcd3296d9e4afca487a272a50 /src | |
parent | 5134ceb34174fd64512d4d60e53ee8a1e476bb86 (diff) | |
download | rspamd-89252bcf03a2213a72f348e210240bb96848e5aa.tar.gz rspamd-89252bcf03a2213a72f348e210240bb96848e5aa.zip |
[Fix] Fix crash with cname replies
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/lua_http.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index a53145c7c..4e8d98abb 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -20,6 +20,7 @@ #include "ref.h" #include "unix-std.h" #include "zlib.h" +#include "utlist.h" /*** * @module rspamd_http @@ -511,28 +512,40 @@ lua_http_dns_handler (struct rdns_reply *reply, gpointer ud) REF_RELEASE (cbd); } else { - if (reply->entries->type == RDNS_REQUEST_A) { - cbd->addr = rspamd_inet_address_new (AF_INET, - &reply->entries->content.a.addr); + struct rdns_reply_entry *entry; + + 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) { + lua_http_push_error (cbd, "unable to resolve host: no records with such name"); + REF_RELEASE (cbd); } + else { + REF_RETAIN (cbd); + if (!lua_http_make_connection(cbd)) { + lua_http_push_error(cbd, "unable to make connection to the host"); - REF_RETAIN (cbd); - if (!lua_http_make_connection (cbd)) { - lua_http_push_error (cbd, "unable to make connection to the host"); + if (cbd->ref.refcount > 1) { + REF_RELEASE (cbd); + } - if (cbd->ref.refcount > 1) { REF_RELEASE (cbd); - } + return; + } REF_RELEASE (cbd); - - return; } - REF_RELEASE (cbd); } if (item) { |