From 44c8d23e9faddacd86671cda9cec69317df1fe5f Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 20 Jan 2022 14:30:48 +0000 Subject: Fix parsing LIST commands with multiple constraints. --- src/coremods/core_list.cpp | 75 ++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 36 deletions(-) (limited to 'src/coremods') diff --git a/src/coremods/core_list.cpp b/src/coremods/core_list.cpp index 28ea91ce1..e128a6a17 100644 --- a/src/coremods/core_list.cpp +++ b/src/coremods/core_list.cpp @@ -95,46 +95,49 @@ CmdResult CommandList::Handle(User* user, const Params& parameters) size_t minusers = 0; size_t maxusers = 0; - for (Params::const_iterator iter = parameters.begin(); iter != parameters.end(); ++iter) + if (!parameters.empty()) { - const std::string& constraint = *iter; - if (constraint[0] == '<') + irc::commasepstream constraints(parameters[0]); + for (std::string constraint; constraints.GetToken(constraint); ) { - maxusers = ConvToNum(constraint.c_str() + 1); - } - else if (constraint[0] == '>') - { - minusers = ConvToNum(constraint.c_str() + 1); - } - else if (!constraint.compare(0, 2, "C<", 2) || !constraint.compare(0, 2, "c<", 2)) - { - mincreationtime = ParseMinutes(constraint); - } - else if (!constraint.compare(0, 2, "C>", 2) || !constraint.compare(0, 2, "c>", 2)) - { - maxcreationtime = ParseMinutes(constraint); - } - else if (!constraint.compare(0, 2, "T<", 2) || !constraint.compare(0, 2, "t<", 2)) - { - mintopictime = ParseMinutes(constraint); - } - else if (!constraint.compare(0, 2, "T>", 2) || !constraint.compare(0, 2, "t>", 2)) - { - maxtopictime = ParseMinutes(constraint); - } - else - { - // If the glob is prefixed with ! it is inverted. - match = constraint.c_str(); - if (match[0] == '!') + if (constraint[0] == '<') { - match_inverted = true; - match += 1; + maxusers = ConvToNum(constraint.c_str() + 1); + } + else if (constraint[0] == '>') + { + minusers = ConvToNum(constraint.c_str() + 1); + } + else if (!constraint.compare(0, 2, "C<", 2) || !constraint.compare(0, 2, "c<", 2)) + { + mincreationtime = ParseMinutes(constraint); + } + else if (!constraint.compare(0, 2, "C>", 2) || !constraint.compare(0, 2, "c>", 2)) + { + maxcreationtime = ParseMinutes(constraint); + } + else if (!constraint.compare(0, 2, "T<", 2) || !constraint.compare(0, 2, "t<", 2)) + { + mintopictime = ParseMinutes(constraint); + } + else if (!constraint.compare(0, 2, "T>", 2) || !constraint.compare(0, 2, "t>", 2)) + { + maxtopictime = ParseMinutes(constraint); + } + else + { + // If the glob is prefixed with ! it is inverted. + match = constraint.c_str(); + if (match[0] == '!') + { + match_inverted = true; + match += 1; + } + + // Ensure that the user didn't just run "LIST !". + if (match[0]) + match_name_topic = true; } - - // Ensure that the user didn't just run "LIST !". - if (match[0]) - match_name_topic = true; } } -- cgit v1.3.1-10-gc9f91 From 1373c45ccac3128633d3c6e6567693087080c0a7 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 20 Jan 2022 14:51:22 +0000 Subject: Fix parsing a LIST request with both a match and inverted match. e.g. /LIST *foo* !*bar* --- src/coremods/core_list.cpp | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'src/coremods') diff --git a/src/coremods/core_list.cpp b/src/coremods/core_list.cpp index e128a6a17..ea9485f8a 100644 --- a/src/coremods/core_list.cpp +++ b/src/coremods/core_list.cpp @@ -79,10 +79,10 @@ CmdResult CommandList::Handle(User* user, const Params& parameters) time_t maxcreationtime = 0; // M: Searching based on mask. + std::string match; + // N: Searching based on !mask. - bool match_name_topic = false; - bool match_inverted = false; - const char* match = NULL; + std::string notmatch; // T: Searching based on topic time, via the "Tval" modifiers to // search for a topic time that is lower or higher than val respectively. @@ -124,19 +124,15 @@ CmdResult CommandList::Handle(User* user, const Params& parameters) { maxtopictime = ParseMinutes(constraint); } - else + else if (constraint[0] == '!') { - // If the glob is prefixed with ! it is inverted. - match = constraint.c_str(); - if (match[0] == '!') - { - match_inverted = true; - match += 1; - } - // Ensure that the user didn't just run "LIST !". - if (match[0]) - match_name_topic = true; + if (constraint.length() > 2) + notmatch = constraint.substr(1); + } + else + { + match = constraint; } } } @@ -165,18 +161,12 @@ CmdResult CommandList::Handle(User* user, const Params& parameters) continue; // Attempt to match a glob pattern. - if (match_name_topic) - { - bool matches = InspIRCd::Match(chan->name, match) || InspIRCd::Match(chan->topic, match); - - // The user specified an match that we did not match. - if (!matches && !match_inverted) - continue; + if (!match.empty() && !InspIRCd::Match(chan->name, match) && !InspIRCd::Match(chan->topic, match)) + continue; - // The user specified an inverted match that we did match. - if (matches && match_inverted) - continue; - } + // Attempt to match an inverted glob pattern. + if (!notmatch.empty() && (InspIRCd::Match(chan->name, notmatch) || InspIRCd::Match(chan->topic, notmatch))) + continue; // if the channel is not private/secret, OR the user is on the channel anyway bool n = (has_privs || chan->HasUser(user)); -- cgit v1.3.1-10-gc9f91