commit af3994a: [Project] Rdns: Do not treat TCP channels failure as fatal

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Jan 5 11:28:08 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-01-02 10:34:05 +0000
URL: https://github.com/rspamd/rspamd/commit/af3994ae7d27e935228fb866103d94310de974c3

[Project] Rdns: Do not treat TCP channels failure as fatal

---
 contrib/librdns/resolver.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/contrib/librdns/resolver.c b/contrib/librdns/resolver.c
index 6ef6d4558..05d838317 100644
--- a/contrib/librdns/resolver.c
+++ b/contrib/librdns/resolver.c
@@ -935,28 +935,46 @@ rdns_resolver_init (struct rdns_resolver *resolver)
 	/* Now init io channels to all servers */
 	UPSTREAM_FOREACH (resolver->servers, serv) {
 		serv->io_channels = calloc (serv->io_cnt, sizeof (struct rdns_io_channel *));
+
+		if (serv->io_channels == NULL) {
+			rdns_err ("cannot allocate memory for the resolver IO channels");
+			return false;
+		}
+
 		for (i = 0; i < serv->io_cnt; i ++) {
 			ioc = rdns_ioc_new(serv, resolver, false);
 
 			if (ioc == NULL) {
-				rdns_err ("cannot allocate memory for the resolver IO channels");
+				rdns_err ("cannot allocate memory or init the IO channel");
 				return false;
 			}
 
 			serv->io_channels[i] = ioc;
 		}
 
+		int ntcp_channels = 0;
+
+		/*
+		 * We are more forgiving for TCP IO channels: we can have zero of them
+		 * if DNS is misconfigured and still be able to resolve stuff
+		 */
 		serv->tcp_io_channels = calloc (serv->tcp_io_cnt, sizeof (struct rdns_io_channel *));
+		if (serv->tcp_io_channels == NULL) {
+			rdns_err ("cannot allocate memory for the resolver TCP IO channels");
+			return false;
+		}
 		for (i = 0; i < serv->tcp_io_cnt; i ++) {
 			ioc = rdns_ioc_new (serv, resolver, true);
 
 			if (ioc == NULL) {
-				rdns_err ("cannot allocate memory for the resolver IO channels");
-				return false;
+				rdns_err ("cannot allocate memory or init the TCP IO channel");
+				continue;
 			}
 
-			serv->tcp_io_channels[i] = ioc;
+			serv->tcp_io_channels[ntcp_channels++] = ioc;
 		}
+
+		serv->tcp_io_cnt = ntcp_channels;
 	}
 
 	if (resolver->async->add_periodic) {


More information about the Commits mailing list