diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-04-07 01:33:11 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-04-07 01:33:11 +0000 |
commit | 4a2bc56abe43ed11283768584e0ca87f224e66ff (patch) | |
tree | 6ea31de5a155ecdb536824a3280cef3030f8121a /src/message.cpp | |
parent | 669f7bb7dd8008ee80e3351e8f186696c8a75178 (diff) |
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
Diffstat (limited to 'src/message.cpp')
-rw-r--r-- | src/message.cpp | 76 |
1 files changed, 36 insertions, 40 deletions
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<ircd_module*> 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)<T)); + std::string ipaddr = d.GetResult(); + strlcpy(resolvedHost,ipaddr.c_str(),MAXBUF); + return (ipaddr != ""); } int c_count(userrec* u) |