Commit 8934a4bc4d4135e30e8663bee8b6154230d58a9e
1 parent
e27053fa
Prevent insertion of null clients in client list
There was a null dereference on a call of member function Client::sendOrQueueWill(). Null clients shouldn exist in the list and this was the only place it could have come from. But, I never got proof.
Showing
1 changed file
with
7 additions
and
1 deletions
threaddata.cpp
| ... | ... | @@ -294,7 +294,13 @@ void ThreadData::giveClient(std::shared_ptr<Client> client) |
| 294 | 294 | std::shared_ptr<Client> ThreadData::getClient(int fd) |
| 295 | 295 | { |
| 296 | 296 | std::lock_guard<std::mutex> lck(clients_by_fd_mutex); |
| 297 | - return this->clients_by_fd[fd]; | |
| 297 | + | |
| 298 | + auto pos = clients_by_fd.find(fd); | |
| 299 | + | |
| 300 | + if (pos == clients_by_fd.end()) | |
| 301 | + return std::shared_ptr<Client>(); | |
| 302 | + | |
| 303 | + return pos->second; | |
| 298 | 304 | } |
| 299 | 305 | |
| 300 | 306 | void ThreadData::removeClientQueued(const std::shared_ptr<Client> &client) | ... | ... |