From aac9fe1921a1c46aad240aa0fb990e7907782cf0 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 9 Dec 2022 10:17:36 +0000 Subject: Fix sending malformed MOTD and showfile messages to clients. --- src/modules/m_opermotd.cpp | 20 ++++++++++++++------ src/modules/m_showfile.cpp | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_opermotd.cpp b/src/modules/m_opermotd.cpp index e833af282..3364b5a5a 100644 --- a/src/modules/m_opermotd.cpp +++ b/src/modules/m_opermotd.cpp @@ -74,12 +74,8 @@ class CommandOpermotd : public Command } user->WriteRemoteNumeric(RPL_OMOTDSTART, "Server operators message of the day"); - for (file_cache::const_iterator i = opermotd.begin(); i != opermotd.end(); ++i) - { - user->WriteRemoteNumeric(RPL_OMOTD, InspIRCd::Format(" %s", i->c_str())); - } - + user->WriteRemoteNumeric(RPL_OMOTD, *i); user->WriteRemoteNumeric(RPL_ENDOFOMOTD, "End of OPERMOTD"); } }; @@ -116,7 +112,19 @@ class ModuleOpermotd : public Module try { FileReader reader(conf->getString("file", "opermotd", 1)); - cmd.opermotd = reader.GetVector(); + + const file_cache& lines = reader.GetVector(); + + // Process the MOTD entry. + cmd.opermotd.reserve(lines.size()); + for (file_cache::const_iterator it = lines.begin(); it != lines.end(); ++it) + { + // Some clients can not handle receiving RPL_OMOTD with an empty + // trailing parameter so if a line is empty we replace it with + // a single space. + const std::string& line = *it; + cmd.opermotd.push_back(line.empty() ? " " : line); + } InspIRCd::ProcessColors(cmd.opermotd); } catch (CoreException&) diff --git a/src/modules/m_showfile.cpp b/src/modules/m_showfile.cpp index ba3dc60e1..80dcf95d0 100644 --- a/src/modules/m_showfile.cpp +++ b/src/modules/m_showfile.cpp @@ -60,7 +60,7 @@ class CommandShowFile : public Command user->WriteRemoteNumeric(intronumeric, introtext); for (file_cache::const_iterator i = contents.begin(); i != contents.end(); ++i) - user->WriteRemoteNumeric(textnumeric, InspIRCd::Format(" %s", i->c_str())); + user->WriteRemoteNumeric(textnumeric, *i); if (!endtext.empty() && endnumeric) user->WriteRemoteNumeric(endnumeric, endtext.c_str()); @@ -93,7 +93,17 @@ class CommandShowFile : public Command else if (smethod == "notice") method = SF_NOTICE; - contents = filecontents; + // Process the entry. + contents.clear(); + contents.reserve(filecontents.size()); + for (file_cache::const_iterator it = filecontents.begin(); it != filecontents.end(); ++it) + { + // Some clients can not handle receiving NOTICE/PRIVMSG/RPL_RULES + // with an empty trailing parameter so if a line is empty we + // replace it with a single space. + const std::string& line = *it; + contents.push_back(line.empty() ? " " : line); + } InspIRCd::ProcessColors(contents); } }; -- cgit v1.3.1-10-gc9f91