diff options
author | Peter Powell <petpow@saberuk.com> | 2018-12-12 20:34:46 +0000 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2018-12-12 21:43:24 +0000 |
commit | 0f7cfd46ef2d277f5f82e34a2852c75212d75261 (patch) | |
tree | 73445b54ad2ce50ae75999ec9f939ff1097b057a /src | |
parent | 4e0cb28c1913c4ef76dd06b04fe321afe310f232 (diff) |
Fix conversion issues by replacing ConvToInt with ConvToNum<T>.
The former was a thin wrapper around atol and brought with it all
of the weird parsing logic of atol which is almost never what is
actually wanted. It also almost never returned the numeric type
which is actually wanted which can cause weird issues when casting.
Diffstat (limited to 'src')
27 files changed, 40 insertions, 40 deletions
diff --git a/src/base.cpp b/src/base.cpp index f698bad2e..8749aee8e 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -278,7 +278,7 @@ std::string LocalIntExt::serialize(SerializeFormat format, const Extensible* con void LocalIntExt::unserialize(SerializeFormat format, Extensible* container, const std::string& value) { if (format != FORMAT_NETWORK) - set(container, ConvToInt(value)); + set(container, ConvToNum<intptr_t>(value)); } intptr_t LocalIntExt::get(const Extensible* container) const diff --git a/src/channels.cpp b/src/channels.cpp index e25500892..e5fd7265e 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -178,7 +178,7 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co unsigned int maxchans = user->GetClass()->maxchans; if (user->IsOper()) { - unsigned int opermaxchans = ConvToInt(user->oper->getConfig("maxchans")); + unsigned int opermaxchans = ConvToNum<unsigned int>(user->oper->getConfig("maxchans")); // If not set, use 2.0's <channels:opers>, if that's not set either, use limit from CC if (!opermaxchans && user->HasPrivPermission("channels/high-join-limit")) opermaxchans = ServerInstance->Config->OperMaxChans; diff --git a/src/coremods/core_channel/cmd_invite.cpp b/src/coremods/core_channel/cmd_invite.cpp index 1b480aa20..ebb95f1b4 100644 --- a/src/coremods/core_channel/cmd_invite.cpp +++ b/src/coremods/core_channel/cmd_invite.cpp @@ -53,7 +53,7 @@ CmdResult CommandInvite::Handle(User* user, const Params& parameters) if (IS_LOCAL(user)) timeout = ServerInstance->Time() + InspIRCd::Duration(parameters[2]); else if (parameters.size() > 3) - timeout = ConvToInt(parameters[3]); + timeout = ConvToNum<time_t>(parameters[3]); } if (!c) @@ -75,7 +75,7 @@ CmdResult CommandInvite::Handle(User* user, const Params& parameters) return CMD_INVALID; // Drop the invite if our channel TS is lower - time_t RemoteTS = ConvToInt(parameters[2]); + time_t RemoteTS = ConvToNum<time_t>(parameters[2]); if (c->age < RemoteTS) return CMD_FAILURE; } diff --git a/src/coremods/core_channel/invite.cpp b/src/coremods/core_channel/invite.cpp index 7ac662edc..51fb638f8 100644 --- a/src/coremods/core_channel/invite.cpp +++ b/src/coremods/core_channel/invite.cpp @@ -162,7 +162,7 @@ void Invite::APIImpl::Unserialize(LocalUser* user, const std::string& value) { Channel* chan = ServerInstance->FindChan(channame); if (chan) - Create(user, chan, ConvToInt(exptime)); + Create(user, chan, ConvToNum<time_t>(exptime)); } } diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index 40cbc3506..3810fcf32 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -99,7 +99,7 @@ struct CallerIDExtInfo : public ExtensionItem irc::commasepstream s(value); std::string tok; if (s.GetToken(tok)) - dat->lastnotify = ConvToInt(tok); + dat->lastnotify = ConvToNum<time_t>(tok); while (s.GetToken(tok)) { diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp index 08f4291c9..47e27172c 100644 --- a/src/modules/m_chanhistory.cpp +++ b/src/modules/m_chanhistory.cpp @@ -71,7 +71,7 @@ class HistoryMode : public ParamMode<HistoryMode, SimpleExtItem<HistoryList> > return MODEACTION_DENY; } - unsigned int len = ConvToInt(parameter.substr(0, colon)); + unsigned int len = ConvToNum<unsigned int>(parameter.substr(0, colon)); unsigned int time = InspIRCd::Duration(duration); if (len == 0 || (len > maxlines && IS_LOCAL(source))) { diff --git a/src/modules/m_delaymsg.cpp b/src/modules/m_delaymsg.cpp index b39fb1d0a..9015e7bf9 100644 --- a/src/modules/m_delaymsg.cpp +++ b/src/modules/m_delaymsg.cpp @@ -38,7 +38,7 @@ class DelayMsgMode : public ParamMode<DelayMsgMode, LocalIntExt> ModeAction OnSet(User* source, Channel* chan, std::string& parameter) CXX11_OVERRIDE; void OnUnset(User* source, Channel* chan); - void SerializeParam(Channel* chan, int n, std::string& out) + void SerializeParam(Channel* chan, intptr_t n, std::string& out) { out += ConvToStr(n); } @@ -62,8 +62,8 @@ class ModuleDelayMsg : public Module ModeAction DelayMsgMode::OnSet(User* source, Channel* chan, std::string& parameter) { // Setting a new limit, sanity check - unsigned int limit = ConvToInt(parameter); - if (limit == 0) + intptr_t limit = ConvToNum<intptr_t>(parameter); + if (limit <= 0) limit = 1; ext.set(chan, limit); diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 584bfef00..cfba6c067 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -637,7 +637,7 @@ FilterResult ModuleFilter::DecodeFilter(const std::string &data) std::string duration; tokens.GetMiddle(duration); - res.duration = ConvToInt(duration); + res.duration = ConvToNum<long>(duration); tokens.GetTrailing(res.reason); diff --git a/src/modules/m_joinflood.cpp b/src/modules/m_joinflood.cpp index aaf266216..cc62eb13b 100644 --- a/src/modules/m_joinflood.cpp +++ b/src/modules/m_joinflood.cpp @@ -109,8 +109,8 @@ class JoinFlood : public ParamMode<JoinFlood, SimpleExtItem<joinfloodsettings> > } /* Set up the flood parameters for this channel */ - unsigned int njoins = ConvToInt(parameter.substr(0, colon)); - unsigned int nsecs = ConvToInt(parameter.substr(colon+1)); + unsigned int njoins = ConvToNum<unsigned int>(parameter.substr(0, colon)); + unsigned int nsecs = ConvToNum<unsigned int>(parameter.substr(colon+1)); if ((njoins<1) || (nsecs<1)) { source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter)); diff --git a/src/modules/m_jumpserver.cpp b/src/modules/m_jumpserver.cpp index fc13a831c..02950e0e9 100644 --- a/src/modules/m_jumpserver.cpp +++ b/src/modules/m_jumpserver.cpp @@ -103,8 +103,8 @@ class CommandJumpserver : public Command } size_t delimpos = parameters[1].find(':'); - port = ConvToInt(parameters[1].substr(0, delimpos ? delimpos : std::string::npos)); - sslport = (delimpos == std::string::npos ? 0 : ConvToInt(parameters[1].substr(delimpos + 1))); + port = ConvToNum<int>(parameters[1].substr(0, delimpos ? delimpos : std::string::npos)); + sslport = (delimpos == std::string::npos ? 0 : ConvToNum<int>(parameters[1].substr(delimpos + 1))); if (parameters[1].find_first_not_of("0123456789:") != std::string::npos || parameters[1].rfind(':') != delimpos diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index 4d911e78b..70f3578b2 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -101,14 +101,14 @@ class KickRejoin : public ParamMode<KickRejoin, SimpleExtItem<KickRejoinData> > ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE { - int v = ConvToInt(parameter); + unsigned int v = ConvToNum<unsigned int>(parameter); if (v <= 0) { source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter)); return MODEACTION_DENY; } - if ((IS_LOCAL(source) && ((unsigned int)v > max))) + if (IS_LOCAL(source) && v > max) v = max; ext.set(channel, new KickRejoinData(v)); diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index 0707e6ae4..af976afd5 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -83,8 +83,8 @@ class MsgFlood : public ParamMode<MsgFlood, SimpleExtItem<floodsettings> > /* Set up the flood parameters for this channel */ bool ban = (parameter[0] == '*'); - unsigned int nlines = ConvToInt(parameter.substr(ban ? 1 : 0, ban ? colon-1 : colon)); - unsigned int nsecs = ConvToInt(parameter.substr(colon+1)); + unsigned int nlines = ConvToNum<unsigned int>(parameter.substr(ban ? 1 : 0, ban ? colon-1 : colon)); + unsigned int nsecs = ConvToNum<unsigned int>(parameter.substr(colon+1)); if ((nlines<2) || (nsecs<1)) { diff --git a/src/modules/m_nickflood.cpp b/src/modules/m_nickflood.cpp index 50e2b3d93..ce8b364e4 100644 --- a/src/modules/m_nickflood.cpp +++ b/src/modules/m_nickflood.cpp @@ -100,8 +100,8 @@ class NickFlood : public ParamMode<NickFlood, SimpleExtItem<nickfloodsettings> > } /* Set up the flood parameters for this channel */ - unsigned int nnicks = ConvToInt(parameter.substr(0, colon)); - unsigned int nsecs = ConvToInt(parameter.substr(colon+1)); + unsigned int nnicks = ConvToNum<unsigned int>(parameter.substr(0, colon)); + unsigned int nsecs = ConvToNum<unsigned int>(parameter.substr(colon+1)); if ((nnicks<1) || (nsecs<1)) { diff --git a/src/modules/m_pbkdf2.cpp b/src/modules/m_pbkdf2.cpp index 89bc39ef4..86530c5dd 100644 --- a/src/modules/m_pbkdf2.cpp +++ b/src/modules/m_pbkdf2.cpp @@ -43,7 +43,7 @@ class PBKDF2Hash std::string tok; ss.GetToken(tok); - this->iterations = ConvToInt(tok); + this->iterations = ConvToNum<unsigned int>(tok); ss.GetToken(tok); this->hash = Base64ToBin(tok); diff --git a/src/modules/m_repeat.cpp b/src/modules/m_repeat.cpp index ef62e9ab1..af69f6be1 100644 --- a/src/modules/m_repeat.cpp +++ b/src/modules/m_repeat.cpp @@ -274,7 +274,7 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> > else settings.Action = ChannelSettings::ACT_KICK; - if ((settings.Lines = ConvToInt(item)) == 0) + if ((settings.Lines = ConvToNum<unsigned int>(item)) == 0) return false; if ((!stream.GetToken(item)) || ((settings.Seconds = InspIRCd::Duration(item)) == 0)) @@ -286,13 +286,13 @@ class RepeatMode : public ParamMode<RepeatMode, SimpleExtItem<ChannelSettings> > if (stream.GetToken(item)) { // There is a diff parameter, see if it's valid (> 0) - if ((settings.Diff = ConvToInt(item)) == 0) + if ((settings.Diff = ConvToNum<unsigned int>(item)) == 0) return false; if (stream.GetToken(item)) { // There is a backlog parameter, see if it's valid - if ((settings.Backlog = ConvToInt(item)) == 0) + if ((settings.Backlog = ConvToNum<unsigned int>(item)) == 0) return false; // If there are still tokens, then it's invalid because we allow only 4 diff --git a/src/modules/m_spanningtree/addline.cpp b/src/modules/m_spanningtree/addline.cpp index 00ef5b8d1..623942d95 100644 --- a/src/modules/m_spanningtree/addline.cpp +++ b/src/modules/m_spanningtree/addline.cpp @@ -38,14 +38,14 @@ CmdResult CommandAddLine::Handle(User* usr, Params& params) XLine* xl = NULL; try { - xl = xlf->Generate(ServerInstance->Time(), ConvToInt(params[4]), params[2], params[5], params[1]); + xl = xlf->Generate(ServerInstance->Time(), ConvToNum<long>(params[4]), params[2], params[5], params[1]); } catch (ModuleException &e) { ServerInstance->SNO->WriteToSnoMask('x',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason().c_str()); return CMD_FAILURE; } - xl->SetCreateTime(ConvToInt(params[3])); + xl->SetCreateTime(ConvToNum<time_t>(params[3])); if (ServerInstance->XLines->AddLine(xl, NULL)) { if (xl->duration) diff --git a/src/modules/m_spanningtree/away.cpp b/src/modules/m_spanningtree/away.cpp index 282f52a35..13972589b 100644 --- a/src/modules/m_spanningtree/away.cpp +++ b/src/modules/m_spanningtree/away.cpp @@ -28,7 +28,7 @@ CmdResult CommandAway::HandleRemote(::RemoteUser* u, Params& params) if (!params.empty()) { if (params.size() > 1) - u->awaytime = ConvToInt(params[0]); + u->awaytime = ConvToNum<time_t>(params[0]); else u->awaytime = ServerInstance->Time(); diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp index 5daea5202..c29330516 100644 --- a/src/modules/m_spanningtree/capab.cpp +++ b/src/modules/m_spanningtree/capab.cpp @@ -249,7 +249,7 @@ bool TreeSocket::Capab(const CommandBase::Params& params) capab->OptModuleList.clear(); capab->CapKeys.clear(); if (params.size() > 1) - proto_version = ConvToInt(params[1]); + proto_version = ConvToNum<unsigned int>(params[1]); if (proto_version < MinCompatProtocol) { diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp index b2967af3b..8e5361b16 100644 --- a/src/modules/m_spanningtree/compat.cpp +++ b/src/modules/m_spanningtree/compat.cpp @@ -521,7 +521,7 @@ bool TreeSocket::PreProcessOldProtocolMessage(User*& who, std::string& cmd, Comm // See if it's a numeric being sent to the target via PUSH unsigned int numeric_number = 0; if (token.length() == 3) - numeric_number = ConvToInt(token); + numeric_number = ConvToNum<unsigned int>(token); if ((numeric_number > 0) && (numeric_number < 1000)) { diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index d619c43bc..4f8875a02 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -40,8 +40,8 @@ * Failure to document your protocol changes will result in a painfully * painful death by pain. You have been warned. */ -const long ProtocolVersion = 1205; -const long MinCompatProtocol = 1202; +const unsigned int ProtocolVersion = 1205; +const unsigned int MinCompatProtocol = 1202; /** Forward declarations */ diff --git a/src/modules/m_spanningtree/num.cpp b/src/modules/m_spanningtree/num.cpp index f83f91286..564b808fd 100644 --- a/src/modules/m_spanningtree/num.cpp +++ b/src/modules/m_spanningtree/num.cpp @@ -33,7 +33,7 @@ CmdResult CommandNum::HandleServer(TreeServer* server, CommandBase::Params& para if (!localtarget) return CMD_SUCCESS; - Numeric::Numeric numeric(ConvToInt(params[2])); + Numeric::Numeric numeric(ConvToNum<unsigned int>(params[2])); // Passing NULL is ok, in that case the numeric source becomes this server numeric.SetServer(Utils->FindServerID(params[0])); numeric.GetParams().insert(numeric.GetParams().end(), params.begin()+3, params.end()); diff --git a/src/modules/m_spanningtree/servercommand.cpp b/src/modules/m_spanningtree/servercommand.cpp index 5b8152846..2f5c7ea3e 100644 --- a/src/modules/m_spanningtree/servercommand.cpp +++ b/src/modules/m_spanningtree/servercommand.cpp @@ -40,7 +40,7 @@ RouteDescriptor ServerCommand::GetRouting(User* user, const Params& parameters) time_t ServerCommand::ExtractTS(const std::string& tsstr) { - time_t TS = ConvToInt(tsstr); + time_t TS = ConvToNum<time_t>(tsstr); if (!TS) throw ProtocolException("Invalid TS"); return TS; diff --git a/src/modules/m_spanningtree/svsnick.cpp b/src/modules/m_spanningtree/svsnick.cpp index 2514dfd6f..a734dc8ed 100644 --- a/src/modules/m_spanningtree/svsnick.cpp +++ b/src/modules/m_spanningtree/svsnick.cpp @@ -47,7 +47,7 @@ CmdResult CommandSVSNick::Handle(User* user, Params& parameters) // won't happen because the timestamps won't match. if (parameters.size() > 3) { - time_t ExpectedTS = ConvToInt(parameters[3]); + time_t ExpectedTS = ConvToNum<time_t>(parameters[3]); if (u->age != ExpectedTS) return CMD_FAILURE; // Ignore SVSNICK } @@ -56,7 +56,7 @@ CmdResult CommandSVSNick::Handle(User* user, Params& parameters) if (isdigit(nick[0])) nick = u->uuid; - time_t NickTS = ConvToInt(parameters[2]); + time_t NickTS = ConvToNum<time_t>(parameters[2]); if (NickTS <= 0) return CMD_FAILURE; diff --git a/src/modules/m_spanningtree/treesocket.h b/src/modules/m_spanningtree/treesocket.h index e8dbfd7cf..36dd8bb93 100644 --- a/src/modules/m_spanningtree/treesocket.h +++ b/src/modules/m_spanningtree/treesocket.h @@ -95,7 +95,7 @@ class TreeSocket : public BufferedSocket ServerState LinkState; /* Link state */ CapabData* capab; /* Link setup data (held until burst is sent) */ TreeServer* MyRoot; /* The server we are talking to */ - int proto_version; /* Remote protocol version */ + unsigned int proto_version; /* Remote protocol version */ /** True if we've sent our burst. * This only changes the behavior of message translation for 1202 protocol servers and it can be diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 513fa6dbf..293cdd695 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -148,7 +148,7 @@ void TreeSocket::ProcessLine(std::string &line) { if (params.size()) { - time_t them = ConvToInt(params[0]); + time_t them = ConvToNum<time_t>(params[0]); time_t delta = them - ServerInstance->Time(); if ((delta < -600) || (delta > 600)) { diff --git a/src/modules/m_topiclock.cpp b/src/modules/m_topiclock.cpp index c65f27668..b0d004b1c 100644 --- a/src/modules/m_topiclock.cpp +++ b/src/modules/m_topiclock.cpp @@ -48,7 +48,7 @@ class CommandSVSTOPIC : public Command if (parameters.size() == 4) { // 4 parameter version, set all topic data on the channel to the ones given in the parameters - time_t topicts = ConvToInt(parameters[1]); + time_t topicts = ConvToNum<time_t>(parameters[1]); if (!topicts) { ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Received SVSTOPIC with a 0 topicts, dropped."); diff --git a/src/socket.cpp b/src/socket.cpp index cdbc83e44..d48a1907c 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -354,7 +354,7 @@ irc::sockets::cidr_mask::cidr_mask(const std::string& mask) } else { - int range = ConvToInt(mask.substr(bits_chars + 1)); + unsigned char range = ConvToNum<unsigned char>(mask.substr(bits_chars + 1)); irc::sockets::aptosa(mask.substr(0, bits_chars), 0, sa); sa2cidr(*this, sa, range); } |