From 8460f081ada5ae3fe98a67e6c52e2646e2446b8a Mon Sep 17 00:00:00 2001 From: brain Date: Mon, 7 May 2007 16:19:22 +0000 Subject: Needs a little testing: Tidyup of some code, namely when validating the length of params for NICK, tidied it into an array of sizes and indexes rather than a big long chain of if, then, else git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6905 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_spanningtree/treesocket.h | 8 ++++ src/modules/m_spanningtree/treesocket1.cpp | 76 +++++++++--------------------- 2 files changed, 29 insertions(+), 55 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_spanningtree/treesocket.h b/src/modules/m_spanningtree/treesocket.h index b5457221a..079d4fe92 100644 --- a/src/modules/m_spanningtree/treesocket.h +++ b/src/modules/m_spanningtree/treesocket.h @@ -398,5 +398,13 @@ class TreeSocket : public InspSocket virtual int OnIncomingConnection(int newsock, char* ip); }; +/* Used to validate the value lengths of multiple parameters for a command */ +struct cmd_validation +{ + const char* item; + size_t param; + size_t length; +}; + #endif diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp index b2e687b2c..7359d8295 100644 --- a/src/modules/m_spanningtree/treesocket1.cpp +++ b/src/modules/m_spanningtree/treesocket1.cpp @@ -766,25 +766,17 @@ bool TreeSocket::ForceJoin(const std::string &source, std::deque &p if (params.size() < 3) return true; - irc::modestacker modestack(true); /* Modes to apply from the users in the user list */ - userrec* who = NULL; /* User we are currently checking */ - std::string channel = params[0]; /* Channel name, as a string */ - time_t TS = atoi(params[1].c_str()); /* Timestamp given to us for remote side */ - irc::tokenstream users(params[2]); /* Users from the user list */ - bool created = false; /* Channel doesnt exist here yet */ - bool apply_other_sides_modes = true; /* True if we are accepting the other side's modes */ - chanrec* chan = this->Instance->FindChan(channel); - time_t ourTS = Instance->Time(true)+600; - - /* Does this channel exist? if it does, get its REAL timestamp */ - if (chan) - ourTS = chan->age; - else - created = true; /* don't perform deops, and set TS to correct time after processing. */ + irc::modestacker modestack(true); /* Modes to apply from the users in the user list */ + userrec* who = NULL; /* User we are currently checking */ + std::string channel = params[0]; /* Channel name, as a string */ + time_t TS = atoi(params[1].c_str()); /* Timestamp given to us for remote side */ + irc::tokenstream users(params[2]); /* Users from the user list */ + bool apply_other_sides_modes = true; /* True if we are accepting the other side's modes */ + chanrec* chan = this->Instance->FindChan(channel); /* The channel we're sending joins to */ + time_t ourTS = chan ? chan->age : Instance->Time(true)+600; /* The TS of our side of the link */ + bool created = !chan; /* True if the channel doesnt exist here yet */ + std::string item; /* One item in the list of nicks */ - /* do this first, so our mode reversals are correctly received by other servers - * if there is a TS collision. - */ params[2] = ":" + params[2]; Utils->DoOneToAllButSender(source,"FJOIN",params,source); @@ -792,11 +784,9 @@ bool TreeSocket::ForceJoin(const std::string &source, std::deque &p if (ourTS < TS) apply_other_sides_modes = false; + /* Our TS greater than theirs, clear all our modes from the channel, accept theirs. */ if (ourTS > TS) { - /* Our TS greater than theirs, clear all our modes from the channel, - * then accept theirs. - */ std::deque param_list; if (Utils->AnnounceTSChange && chan) chan->WriteChannelWithServ(Instance->Config->ServerName, "NOTICE %s :TS for %s changed from %lu to %lu", chan->name, chan->name, ourTS, TS); @@ -809,14 +799,10 @@ bool TreeSocket::ForceJoin(const std::string &source, std::deque &p } } - std::string item; - /* Now, process every 'prefixes,nick' pair */ while (users.GetToken(item)) { - /* Find next user */ const char* usr = item.c_str(); - /* Safety check just to make sure someones not sent us an FJOIN full of spaces or other such craq */ if (usr && *usr) { const char* permissions = usr; @@ -882,9 +868,6 @@ bool TreeSocket::ForceJoin(const std::string &source, std::deque &p delete n; } - /* All done. That wasnt so bad was it, you can wipe - * the sweat from your forehead now. :-) - */ return true; } @@ -900,41 +883,24 @@ bool TreeSocket::IntroduceClient(const std::string &source, std::dequeWriteLine(std::string(":")+this->Instance->Config->ServerName+" KILL "+params[1]+" :Invalid client introduction (Invalid TS?)"); return true; } - else if (params[1].length() > NICKMAX) - { - this->WriteLine(std::string(":")+this->Instance->Config->ServerName+" KILL "+params[1]+" :Invalid client introduction ("+params[1]+" > NICKMAX?)"); - return true; - } - else if (params[2].length() > 64) + for (size_t x = 0; valid[x].length; ++x) { - this->WriteLine(std::string(":")+this->Instance->Config->ServerName+" KILL "+params[1]+" :Invalid client introduction ("+params[2]+" > 64?)"); - return true; - } - else if (params[3].length() > 64) - { - this->WriteLine(std::string(":")+this->Instance->Config->ServerName+" KILL "+params[1]+" :Invalid client introduction ("+params[3]+" > 64?)"); - return true; - } - else if (params[4].length() > IDENTMAX) - { - this->WriteLine(std::string(":")+this->Instance->Config->ServerName+" KILL "+params[1]+" :Invalid client introduction ("+params[4]+" > IDENTMAX?)"); - return true; - } - else if (params[7].length() > MAXGECOS) - { - this->WriteLine(std::string(":")+this->Instance->Config->ServerName+" KILL "+params[1]+" :Invalid client introduction ("+params[7]+" > MAXGECOS?)"); - return true; + if (params[valid[x].param].length() > valid[x].length) + { + this->WriteLine(std::string(":")+this->Instance->Config->ServerName+" KILL "+params[1]+" :Invalid client introduction (" + valid[x].item + " > " + ConvToStr(valid[x].length) + ")"); + return true; + } } /** Our client looks ok, lets introduce it now -- cgit v1.2.3