diff options
author | honghaiz <honghaiz@webrtc.org> | 2015-12-02 16:43:25 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-03 00:43:33 +0000 |
commit | c3e0fe7c21a6c6c367ce38b54634dc38f6222693 (patch) | |
tree | 8bccba4b4bdd5979c80b5765a984ba305554f2ea /webrtc/p2p | |
parent | 7635684130cc3a071d245b607fddec059002e7fa (diff) | |
download | webrtc-c3e0fe7c21a6c6c367ce38b54634dc38f6222693.tar.gz |
Make it extra safe when deleting a turn entry.
Check if it is in the list of turn entries before attempting to delete it.
BUG=
Review URL: https://codereview.webrtc.org/1458013004
Cr-Commit-Position: refs/heads/master@{#10877}
Diffstat (limited to 'webrtc/p2p')
-rw-r--r-- | webrtc/p2p/base/turnport.cc | 8 | ||||
-rw-r--r-- | webrtc/p2p/base/turnport.h | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/webrtc/p2p/base/turnport.cc b/webrtc/p2p/base/turnport.cc index 20c2b6002f..be581ed308 100644 --- a/webrtc/p2p/base/turnport.cc +++ b/webrtc/p2p/base/turnport.cc @@ -907,6 +907,11 @@ TurnEntry* TurnPort::FindEntry(int channel_id) const { return (it != entries_.end()) ? *it : NULL; } +bool TurnPort::EntryExists(TurnEntry* e) { + auto it = std::find(entries_.begin(), entries_.end(), e); + return it != entries_.end(); +} + void TurnPort::CreateOrRefreshEntry(const rtc::SocketAddress& addr) { TurnEntry* entry = FindEntry(addr); if (entry == nullptr) { @@ -928,6 +933,9 @@ void TurnPort::DestroyEntry(TurnEntry* entry) { void TurnPort::DestroyEntryIfNotCancelled(TurnEntry* entry, uint32_t timestamp) { + if (!EntryExists(entry)) { + return; + } bool cancelled = timestamp != entry->destruction_timestamp(); if (!cancelled) { DestroyEntry(entry); diff --git a/webrtc/p2p/base/turnport.h b/webrtc/p2p/base/turnport.h index 0cdc291101..62e3c41580 100644 --- a/webrtc/p2p/base/turnport.h +++ b/webrtc/p2p/base/turnport.h @@ -218,6 +218,7 @@ class TurnPort : public Port { bool HasPermission(const rtc::IPAddress& ipaddr) const; TurnEntry* FindEntry(const rtc::SocketAddress& address) const; TurnEntry* FindEntry(int channel_id) const; + bool EntryExists(TurnEntry* e); void CreateOrRefreshEntry(const rtc::SocketAddress& address); void DestroyEntry(TurnEntry* entry); // Destroys the entry only if |timestamp| matches the destruction timestamp |