From b2c78ffe5972bacf1d511fab99310fd8e39c1fb5 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 30 Sep 2022 20:33:49 +0100 Subject: Prevent allowing weird characters within hostnames. --- src/modules/m_chghost.cpp | 10 ++++++++-- src/modules/m_hostchange.cpp | 10 ++++++++-- src/modules/m_sethost.cpp | 10 ++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_chghost.cpp b/src/modules/m_chghost.cpp index e97526172..9aff5140b 100644 --- a/src/modules/m_chghost.cpp +++ b/src/modules/m_chghost.cpp @@ -101,9 +101,15 @@ public: auto tag = ServerInstance->Config->ConfValue("hostname"); const std::string hmap = tag->getString("charmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789", 1); - cmd.hostmap.reset(); + CharState newhostmap; for (const auto& chr : hmap) - cmd.hostmap.set(static_cast(chr)); + { + // A hostname can not contain NUL, LF, CR, or SPACE. + if (chr == 0x00 || chr == 0x0A || chr == 0x0D || chr == 0x20) + throw ModuleException(this, InspIRCd::Format(" can not contain character 0x%02X (%c)", chr, chr)); + newhostmap.set(static_cast(chr)); + } + std::swap(newhostmap, cmd.hostmap); } }; diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index d6d79286c..d10441f2b 100644 --- a/src/modules/m_hostchange.cpp +++ b/src/modules/m_hostchange.cpp @@ -192,9 +192,15 @@ public: auto tag = ServerInstance->Config->ConfValue("hostname"); const std::string hmap = tag->getString("charmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789", 1); - hostmap.reset(); + CharState newhostmap; for (const auto& chr : hmap) - hostmap.set(static_cast(chr)); + { + // A hostname can not contain NUL, LF, CR, or SPACE. + if (chr == 0x00 || chr == 0x0A || chr == 0x0D || chr == 0x20) + throw ModuleException(this, InspIRCd::Format(" can not contain character 0x%02X (%c)", chr, chr)); + newhostmap.set(static_cast(chr)); + } + std::swap(newhostmap, hostmap); hostrules.swap(rules); } diff --git a/src/modules/m_sethost.cpp b/src/modules/m_sethost.cpp index 769f51cb5..6f563a0d0 100644 --- a/src/modules/m_sethost.cpp +++ b/src/modules/m_sethost.cpp @@ -83,9 +83,15 @@ public: auto tag = ServerInstance->Config->ConfValue("hostname"); const std::string hmap = tag->getString("charmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789", 1); - cmd.hostmap.reset(); + CharState newhostmap; for (const auto& chr : hmap) - cmd.hostmap.set(static_cast(chr)); + { + // A hostname can not contain NUL, LF, CR, or SPACE. + if (chr == 0x00 || chr == 0x0A || chr == 0x0D || chr == 0x20) + throw ModuleException(this, InspIRCd::Format(" can not contain character 0x%02X (%c)", chr, chr)); + newhostmap.set(static_cast(chr)); + } + std::swap(newhostmap, cmd.hostmap); } }; -- cgit v1.3.1-10-gc9f91