From 4a2bc56abe43ed11283768584e0ca87f224e66ff Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 7 Apr 2005 01:33:11 +0000 Subject: Fixed a double free in dnsqueue.cpp Fixed a resolver issue (weird segfault on gentoo?) in server linking git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@995 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/dnsqueue.cpp | 1 + src/inspircd.cpp | 15 ++++++----- src/message.cpp | 76 +++++++++++++++++++++++++++----------------------------- 3 files changed, 46 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp index 7886cf09f..e2230b584 100644 --- a/src/dnsqueue.cpp +++ b/src/dnsqueue.cpp @@ -189,6 +189,7 @@ public: { if (resolver) delete resolver; + resolver = NULL; } bool DoLookup(std::string nick) diff --git a/src/inspircd.cpp b/src/inspircd.cpp index c129fc039..64ba6a8c1 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -3512,14 +3512,17 @@ int InspIRCd(void) char remotehost[MAXBUF],resolved[MAXBUF]; length = sizeof (client); incomingSockfd = accept (me[x]->fd, (sockaddr *) &client, &length); - strlcpy(remotehost,(char *)inet_ntoa(client.sin_addr),MAXBUF); - if(CleanAndResolve(resolved, remotehost) != TRUE) + if (incomingSockfd != -1) { - strlcpy(resolved,remotehost,MAXBUF); + strlcpy(remotehost,(char *)inet_ntoa(client.sin_addr),MAXBUF); + if(CleanAndResolve(resolved, remotehost) != TRUE) + { + strlcpy(resolved,remotehost,MAXBUF); + } + // add to this connections ircd_connector vector + // *FIX* - we need the LOCAL port not the remote port in &client! + me[x]->AddIncoming(incomingSockfd,resolved,me[x]->port); } - // add to this connections ircd_connector vector - // *FIX* - we need the LOCAL port not the remote port in &client! - me[x]->AddIncoming(incomingSockfd,resolved,me[x]->port); } } } diff --git a/src/message.cpp b/src/message.cpp index 2239916c0..9fc057a5f 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -49,6 +49,7 @@ #include "wildcard.h" #include "message.h" #include "inspstring.h" +#include "dns.h" using namespace std; @@ -58,6 +59,9 @@ extern std::vector factory; extern time_t TIME; +extern FILE *log_file; +extern char DNSServer[MAXBUF]; + /* return 0 or 1 depending if users u and u2 share one or more common channels * (used by QUIT, NICK etc which arent channel specific notices) */ @@ -175,59 +179,51 @@ void tidystring(char* str) void chop(char* str) { - if (!str) - { - log(DEBUG,"ERROR! Null string passed to chop()!"); - return; - } - string temp = str; - FOREACH_MOD OnServerRaw(temp,false,NULL); - const char* str2 = temp.c_str(); - snprintf(str,MAXBUF,"%s",str2); - - - if (strlen(str) >= 512) - { - str[509] = '\r'; - str[510] = '\n'; - str[511] = '\0'; - } + if (!str) + { + log(DEBUG,"ERROR! Null string passed to chop()!"); + return; + } + string temp = str; + FOREACH_MOD OnServerRaw(temp,false,NULL); + const char* str2 = temp.c_str(); + snprintf(str,MAXBUF,"%s",str2); + if (strlen(str) >= 512) + { + str[509] = '\r'; + str[510] = '\n'; + str[511] = '\0'; + } } void Blocking(int s) { - int flags; - log(DEBUG,"Blocking: %d",s); - flags = fcntl(s, F_GETFL, 0); - fcntl(s, F_SETFL, flags ^ O_NONBLOCK); + int flags; + log(DEBUG,"Blocking: %d",s); + flags = fcntl(s, F_GETFL, 0); + fcntl(s, F_SETFL, flags ^ O_NONBLOCK); } void NonBlocking(int s) { - int flags; - log(DEBUG,"NonBlocking: %d",s); - flags = fcntl(s, F_GETFL, 0); - //fcntl(s, F_SETFL, O_NONBLOCK); - fcntl(s, F_SETFL, flags | O_NONBLOCK); + int flags; + log(DEBUG,"NonBlocking: %d",s); + flags = fcntl(s, F_GETFL, 0); + fcntl(s, F_SETFL, flags | O_NONBLOCK); } int CleanAndResolve (char *resolvedHost, const char *unresolvedHost) { - struct hostent *hostPtr = NULL; - struct in_addr addr; - - memset (resolvedHost, '\0',MAXBUF); - if(unresolvedHost == NULL) - return(ERROR); - if ((inet_aton(unresolvedHost,&addr)) == 0) - return(ERROR); - hostPtr = gethostbyaddr ((char *)&addr.s_addr,sizeof(addr.s_addr),AF_INET); - if (hostPtr != NULL) - snprintf(resolvedHost,MAXBUF,"%s",hostPtr->h_name); - else - snprintf(resolvedHost,MAXBUF,"%s",unresolvedHost); - return (TRUE); + DNS d(DNSServer); + int fd = d.ReverseLookup(unresolvedHost); + if (fd < 1) + return 0; + time_t T = time(NULL)+1; + while ((!d.HasResult()) && (time(NULL)