diff options
| author | 2021-07-07 14:19:55 +0100 | |
|---|---|---|
| committer | 2021-07-27 16:28:23 +0100 | |
| commit | 0651f91bda6e770dadfe68613d28966d3ee14b95 (patch) | |
| tree | a0c2c6cbe403d2a47accc9c3dbda0e29fe2c7500 /src | |
| parent | Allow retrieving the already sent id from WriteNeighborsWithCap. (diff) | |
Fix a race condition with hostname lookups when using haproxy.
If a user's origin has been changed before the first DNS lookup
returns then the result of the lookup for that origin may overwrite
their host.
Closes #1914.
Diffstat (limited to 'src')
| -rw-r--r-- | src/coremods/core_hostname_lookup.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/coremods/core_hostname_lookup.cpp b/src/coremods/core_hostname_lookup.cpp index 4195e5a78..4c4ab95dc 100644 --- a/src/coremods/core_hostname_lookup.cpp +++ b/src/coremods/core_hostname_lookup.cpp @@ -33,6 +33,9 @@ namespace class UserResolver : public DNS::Request { private: + /** The socket address that the user we are looking up is connected from. */ + const irc::sockets::sockaddrs sa; + /** UUID we are looking up */ const std::string uuid; @@ -57,6 +60,7 @@ class UserResolver : public DNS::Request */ UserResolver(DNS::Manager* mgr, Module* me, LocalUser* user, const std::string& to_resolve, DNS::QueryType qt) : DNS::Request(mgr, me, to_resolve, qt) + , sa(user->client_sa) , uuid(user->uuid) { } @@ -68,11 +72,8 @@ class UserResolver : public DNS::Request void OnLookupComplete(const DNS::Query* r) CXX11_OVERRIDE { LocalUser* bound_user = IS_LOCAL(ServerInstance->FindUUID(uuid)); - if (!bound_user) - { - ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Resolution finished for user '%s' who is gone", uuid.c_str()); + if (!bound_user || bound_user->client_sa != sa) return; - } const DNS::ResourceRecord* ans_record = r->FindAnswerOfType(this->question.type); if (ans_record == NULL) @@ -145,7 +146,7 @@ class UserResolver : public DNS::Request void OnError(const DNS::Query* query) CXX11_OVERRIDE { LocalUser* bound_user = IS_LOCAL(ServerInstance->FindUUID(uuid)); - if (bound_user) + if (bound_user && bound_user->client_sa == sa) HandleError(bound_user, "Could not resolve your hostname: " + this->manager->GetErrorStr(query->error)); } }; |
