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_sethost.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/modules/m_sethost.cpp') 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