]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/resolve.c
security: fix remotely triggerable crash in SSL/TLS code
[ngircd-alex.git] / src / ngircd / resolve.c
index a128694bab19f06033dff4da93737f32bb0094b6..e7f73ad5c3c32cf801ce891c15fa1a45689fcad5 100644 (file)
@@ -14,8 +14,6 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: resolve.c,v 1.29 2008/02/26 22:04:17 fw Exp $";
-
 #include "imp.h"
 #include <assert.h>
 #include <errno.h>
@@ -45,6 +43,10 @@ static void Do_ResolveAddr PARAMS(( const ng_ipaddr_t *Addr, int Sock, int w_fd
 static void Do_ResolveName PARAMS(( const char *Host, int w_fd ));
 static bool register_callback PARAMS((RES_STAT *s, void (*cbfunc)(int, short)));
 
+#ifdef WANT_IPV6
+extern bool Conf_ConnectIPv4;
+extern bool Conf_ConnectIPv6;
+#endif
 
 static pid_t
 Resolver_fork(int *pipefds)
@@ -88,7 +90,7 @@ Resolve_Addr(RES_STAT * s, const ng_ipaddr_t *Addr, int identsock,
 
        pid = Resolver_fork(pipefd);
        if (pid > 0) {
-               Log(LOG_DEBUG, "Resolver for %s created (PID %d).", ng_ipaddr_tostr(Addr), pid);
+               LogDebug("Resolver for %s created (PID %d).", ng_ipaddr_tostr(Addr), pid);
 
                s->pid = pid;
                s->resolver_fd = pipefd[0];
@@ -171,13 +173,12 @@ Do_IdentQuery(int identsock, array *resolved_addr)
 #ifdef IDENTAUTH
        char *res;
 
-       assert(identsock >= 0);
+       if (identsock < 0)
+               return;
 
 #ifdef DEBUG
        Log_Resolver(LOG_DEBUG, "Doing IDENT lookup on socket %d ...", identsock);
 #endif
-       if (identsock < 0)
-               return;
        res = ident_id( identsock, 10 );
 #ifdef DEBUG
        Log_Resolver(LOG_DEBUG, "Ok, IDENT lookup on socket %d done: \"%s\"",
@@ -267,19 +268,29 @@ static bool
 ForwardLookup(const char *hostname, array *IpAddr)
 {
        ng_ipaddr_t addr;
+
 #ifdef HAVE_GETADDRINFO
        int res;
        struct addrinfo *a, *ai_results;
-       static const struct addrinfo hints = {
+       static struct addrinfo hints;
+
 #ifndef WANT_IPV6
-               .ai_family = AF_INET,
+       hints.ai_family = AF_INET;
 #endif
 #ifdef AI_ADDRCONFIG   /* glibc has this, but not e.g. netbsd 4.0 */
-               .ai_flags = AI_ADDRCONFIG,
+       hints.ai_flags = AI_ADDRCONFIG;
+#endif
+       hints.ai_socktype = SOCK_STREAM;
+       hints.ai_protocol = IPPROTO_TCP;
+
+#ifdef WANT_IPV6
+       assert(Conf_ConnectIPv6 || Conf_ConnectIPv4);
+
+       if (!Conf_ConnectIPv6)
+               hints.ai_family = AF_INET;
+       if (!Conf_ConnectIPv4)
+               hints.ai_family = AF_INET6;
 #endif
-               .ai_socktype = SOCK_STREAM,
-               .ai_protocol = IPPROTO_TCP
-       };
        res = getaddrinfo(hostname, NULL, &hints, &ai_results);
        switch (res) {
        case 0: break;