diff options
author | louiz’ <louiz@louiz.org> | 2016-06-23 22:14:32 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2016-06-23 22:16:13 +0200 |
commit | 57263961b487bd839cbce5fe7547933240792fbc (patch) | |
tree | 01dfc25ecf623a7119f86973cb0bea631b49169e | |
parent | c1f678e4503083e56d0bef0386657c083c0117ef (diff) | |
download | biboumi-57263961b487bd839cbce5fe7547933240792fbc.tar.gz biboumi-57263961b487bd839cbce5fe7547933240792fbc.tar.bz2 biboumi-57263961b487bd839cbce5fe7547933240792fbc.tar.xz biboumi-57263961b487bd839cbce5fe7547933240792fbc.zip |
Fix a use after free in IrcChannel::remove_user
-rw-r--r-- | src/irc/irc_channel.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 9801513..e769245 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -37,11 +37,14 @@ IrcUser* IrcChannel::find_user(const std::string& name) const void IrcChannel::remove_user(const IrcUser* user) { - this->users.erase(std::remove_if(this->users.begin(), this->users.end(), - [user](const std::unique_ptr<IrcUser>& u) - { - return user->nick == u->nick; - }), this->users.end()); + const auto nick = user->nick; + const auto it = std::find_if(this->users.begin(), this->users.end(), + [nick](const std::unique_ptr<IrcUser>& u) + { + return nick == u->nick; + }); + if (it != this->users.end()) + this->users.erase(it); } void IrcChannel::remove_all_users() |