X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsocket.cpp;h=abccd04084c3d58a0908898c27805bef9f337296;hb=9b031d4d98e5ca35b960d3f9b2498edf19b02939;hp=cdbc83e444825a7f8f98d377adc54913f339a0fc;hpb=712313ae7cdf2ab81d497dc810a20eee8211c8e9;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/socket.cpp b/src/socket.cpp index cdbc83e44..abccd0408 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -39,7 +39,7 @@ bool InspIRCd::BindPort(ConfigTag* tag, const irc::sockets::sockaddrs& sa, std:: return true; } } - + ListenSocket* ll = new ListenSocket(tag, sa); if (ll->GetFd() < 0) { @@ -100,18 +100,22 @@ int InspIRCd::BindPorts(FailedPortList& failed_ports) { // UNIX socket paths are length limited to less than PATH_MAX. irc::sockets::sockaddrs bindspec; - if (path.length() > std::min(ServerInstance->Config->Limits.MaxHost, sizeof(bindspec.un.sun_path))) + if (path.length() > std::min(ServerInstance->Config->Limits.MaxHost, sizeof(bindspec.un.sun_path) - 1)) { this->Logs->Log("SOCKET", LOG_DEFAULT, "UNIX listener on %s at %s specified a path that is too long!", path.c_str(), tag->getTagLocation().c_str()); continue; } - // Create the bindspec manually (aptosa doesn't work with AF_UNIX yet). - memset(&bindspec, 0, sizeof(bindspec)); - bindspec.un.sun_family = AF_UNIX; - memcpy(&bindspec.un.sun_path, path.c_str(), sizeof(bindspec.un.sun_path)); + // Check for characters which are problematic in the IRC message format. + if (path.find_first_of("\n\r\t!@: ") != std::string::npos) + { + this->Logs->Log("SOCKET", LOG_DEFAULT, "UNIX listener on %s at %s specified a path containing invalid characters!", + path.c_str(), tag->getTagLocation().c_str()); + continue; + } + irc::sockets::untosa(path, bindspec); if (!BindPort(tag, bindspec, old_ports)) failed_ports.push_back(std::make_pair(bindspec, errno)); else @@ -174,6 +178,17 @@ bool irc::sockets::aptosa(const std::string& addr, int port, irc::sockets::socka return false; } +bool irc::sockets::untosa(const std::string& path, irc::sockets::sockaddrs& sa) +{ + memset(&sa, 0, sizeof(sa)); + if (path.length() >= sizeof(sa.un.sun_path)) + return false; + + sa.un.sun_family = AF_UNIX; + memcpy(&sa.un.sun_path, path.c_str(), path.length() + 1); + return true; +} + int irc::sockets::sockaddrs::family() const { return sa.sa_family; @@ -354,7 +369,7 @@ irc::sockets::cidr_mask::cidr_mask(const std::string& mask) } else { - int range = ConvToInt(mask.substr(bits_chars + 1)); + unsigned char range = ConvToNum(mask.substr(bits_chars + 1)); irc::sockets::aptosa(mask.substr(0, bits_chars), 0, sa); sa2cidr(*this, sa, range); }