From bfa93165954ff2f95793fd90235b7f5036916a1b Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 19 Feb 2024 17:40:54 +0000 Subject: Fix more issues with the v3 compat layer. --- src/modules/m_spanningtree/compat.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/modules/m_spanningtree/compat.cpp') diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp index 5dd0c3d45..917b1e480 100644 --- a/src/modules/m_spanningtree/compat.cpp +++ b/src/modules/m_spanningtree/compat.cpp @@ -20,6 +20,17 @@ #include "inspircd.h" #include "main.h" +namespace +{ + size_t NextToken(const std::string& line, size_t start) + { + if (start == std::string::npos || start + 1 > line.length()) + return std::string::npos; + + return line.find(' ', start + 1); + } +} + void TreeSocket::WriteLine(const std::string& original_line) { if (LinkState != CONNECTED || proto_version == PROTO_NEWEST) @@ -34,17 +45,25 @@ void TreeSocket::WriteLine(const std::string& original_line) size_t cmdstart = 0; if (line[0] == '@') // Skip the tags. - cmdstart = line.find(' '); + { + cmdstart = NextToken(line, 0); + if (cmdstart != std::string::npos) + cmdstart++; + } - if (line[cmdstart + 1] == ':') // Skip the prefix. - cmdstart = line.find(' ', cmdstart + 1); + if (line[cmdstart] == ':') // Skip the prefix. + { + cmdstart = NextToken(line, cmdstart); + if (cmdstart != std::string::npos) + cmdstart++; + } // Find the end of the command. - size_t cmdend = line.find(' ', cmdstart + 1); + size_t cmdend = NextToken(line, cmdstart); if (cmdend == std::string::npos) - cmdend = line.size(); + cmdend = line.size() - 1; - std::string command(line, cmdstart + 1, cmdend - cmdstart - 1); + std::string command(line, cmdstart, cmdend - cmdstart); if (proto_version == PROTO_INSPIRCD_3) { if (irc::equals(command, "FRHOST")) @@ -55,7 +74,7 @@ void TreeSocket::WriteLine(const std::string& original_line) else if (irc::equals(command, "SQUERY")) { // SQUERY was introduced in PROTO_INSPIRCD_4; convert to PRIVMSG. - line.replace(cmdstart + 1, cmdend - cmdstart - 1, "PRIVMSG"); + line.replace(cmdstart, 6, "PRIVMSG"); } } -- cgit v1.3.1-10-gc9f91