From 2ddb62319803f6a3f3246a52b4e009d9ae1daaed Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 18 Dec 2022 17:51:35 +0000 Subject: Use in_port_t instead of int/unsigned int/long. --- src/modules/m_gateway.cpp | 4 ++-- src/modules/m_hostchange.cpp | 7 +++++-- src/modules/m_ircv3_sts.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_gateway.cpp b/src/modules/m_gateway.cpp index a43e3ee9b..4e3bdc843 100644 --- a/src/modules/m_gateway.cpp +++ b/src/modules/m_gateway.cpp @@ -480,7 +480,7 @@ public: if (cport != flags->end()) { // If we can't parse the port then just give up. - uint16_t port = ConvToNum(cport->second); + in_port_t port = ConvToNum(cport->second); if (port) { switch (user->client_sa.family()) @@ -506,7 +506,7 @@ public: if (sport != flags->end()) { // If we can't parse the port then just give up. - uint16_t port = ConvToNum(sport->second); + in_port_t port = ConvToNum(sport->second); if (port) { switch (user->server_sa.family()) diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index fda8e7e67..bd3e2b36b 100644 --- a/src/modules/m_hostchange.cpp +++ b/src/modules/m_hostchange.cpp @@ -47,7 +47,7 @@ private: std::string host; std::string klass; std::string mask; - insp::flat_set ports; + insp::flat_set ports; std::string prefix; std::string suffix; @@ -62,7 +62,10 @@ private: { irc::portparser portrange(portlist, false); while (long port = portrange.GetToken()) - ports.insert(port); + { + if (port > std::numeric_limits::min() && port <= std::numeric_limits::max()) + ports.insert(static_cast(port)); + } } } diff --git a/src/modules/m_ircv3_sts.cpp b/src/modules/m_ircv3_sts.cpp index e199b7f34..93004f3f4 100644 --- a/src/modules/m_ircv3_sts.cpp +++ b/src/modules/m_ircv3_sts.cpp @@ -88,7 +88,7 @@ public: // TODO: Send duration=0 when STS vanishes. } - void SetPolicy(const std::string& newhost, unsigned long duration, unsigned int port, bool preload) + void SetPolicy(const std::string& newhost, unsigned long duration, in_port_t port, bool preload) { // To enforce an STS upgrade policy, servers MUST send this key to insecurely connected clients. Servers // MAY send this key to securely connected clients, but it will be ignored. @@ -140,7 +140,7 @@ private: STSCap cap; // The IRCv3 STS specification requires that the server is listening using TLS using a valid certificate. - static bool HasValidSSLPort(unsigned int port) + static bool HasValidSSLPort(in_port_t port) { for (const auto& ls : ServerInstance->ports) { @@ -149,7 +149,7 @@ private: return true; // Is this listener on the right port? - unsigned int saport = ls->bind_sa.port(); + in_port_t saport = ls->bind_sa.port(); if (saport != port) continue; @@ -181,7 +181,7 @@ public: if (host.empty()) throw ModuleException(this, " must contain a hostname, at " + tag->source.str()); - unsigned int port = static_cast(tag->getUInt("port", 0, 0, UINT16_MAX)); + in_port_t port = static_cast(tag->getUInt("port", 0, 0, UINT16_MAX)); if (!HasValidSSLPort(port)) throw ModuleException(this, " must be a TLS port, at " + tag->source.str()); -- cgit v1.3.1-10-gc9f91