From 1fac9bc0b3a73ff9fcbb796910793c9f118d95e4 Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 18 Apr 2006 11:32:53 +0000 Subject: Fix for crashes in m_ident (should work) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3883 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_ident.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index 2c6e40c8c..9136d1349 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -31,7 +31,6 @@ class RFC1413 : public InspSocket { protected: Server* Srv; // Server* class used for core communications - userrec* u; // user record that the lookup is associated with sockaddr_in sock_us; // our port number sockaddr_in sock_them; // their port number socklen_t uslen; // length of our port number @@ -39,6 +38,8 @@ class RFC1413 : public InspSocket char ident_request[128]; // buffer used to make up the request string public: + userrec* u; // user record that the lookup is associated with + RFC1413(userrec* user, int maxtime, Server* S) : InspSocket((char*)inet_ntoa(user->ip4), 113, false, maxtime), Srv(S), u(user) { Srv->Log(DEBUG,"Ident: associated."); @@ -48,8 +49,11 @@ class RFC1413 : public InspSocket { // When we timeout, the connection failed within the allowed timeframe, // so we just display a notice, and tidy off the ident_data. - u->Shrink("ident_data"); - Srv->SendServ(u->fd,"NOTICE "+std::string(u->nick)+" :*** Could not find your ident, using "+std::string(u->ident)+" instead."); + if (u) + { + u->Shrink("ident_data"); + Srv->SendServ(u->fd,"NOTICE "+std::string(u->nick)+" :*** Could not find your ident, using "+std::string(u->ident)+" instead."); + } } virtual bool OnDataReady() @@ -76,9 +80,12 @@ class RFC1413 : public InspSocket *j = '\0'; // truncate at invalid chars if (*section) { - strlcpy(u->ident,section,IDENTMAX); - Srv->Log(DEBUG,"IDENT SET: "+std::string(u->ident)); - Srv->SendServ(u->fd,"NOTICE "+std::string(u->nick)+" :*** Found your ident: "+std::string(u->ident)); + if (u) + { + strlcpy(u->ident,section,IDENTMAX); + Srv->Log(DEBUG,"IDENT SET: "+std::string(u->ident)); + Srv->SendServ(u->fd,"NOTICE "+std::string(u->nick)+" :*** Found your ident: "+std::string(u->ident)); + } } return false; } @@ -94,12 +101,18 @@ class RFC1413 : public InspSocket { // tidy up after ourselves when the connection is done. // We receive this event straight after a timeout, too. - u->Shrink("ident_data"); + if (u) + { + u->Shrink("ident_data"); + } } virtual void OnError(InspSocketError e) { - u->Shrink("ident_data"); + if (u) + { + u->Shrink("ident_data"); + } } virtual bool OnConnected() @@ -197,6 +210,11 @@ class ModuleIdent : public Module RFC1413* ident = (RFC1413*)user->GetExt("ident_data"); if (ident) { + // FIX: If the user record is deleted, the socket wont be removed + // immediately so there is chance of the socket trying to write to + // a user which has now vanished! To prevent this, set ident::u + // to NULL and check it so that we dont write users who have gone away. + ident->u = NULL; Srv->RemoveSocket(ident); } } -- cgit v1.2.3