2
0
Эх сурвалжийг харах

Merge pull request #105 from paullouisageneau/fix-after-free-sctp-incoming

Fix use-after-free in SctpTransport::incoming()
Paul-Louis Ageneau 5 жил өмнө
parent
commit
d87539937e

+ 5 - 0
src/sctptransport.cpp

@@ -194,6 +194,11 @@ SctpTransport::~SctpTransport() {
 }
 
 bool SctpTransport::stop() {
+	// Transport::stop() will unregister incoming() from the lower layer, therefore we need to make
+	// sure the thread from lower layers is not blocked in incoming() by the WrittenOnce condition.
+	mWrittenOnce = true;
+	mWrittenCondition.notify_all();
+
 	if (!Transport::stop())
 		return false;
 

+ 8 - 3
src/transport.hpp

@@ -41,12 +41,17 @@ public:
 
 	virtual ~Transport() {
 		stop();
-		if (mLower)
-			mLower->onRecv(nullptr); // doing it on stop could cause a deadlock
 	}
 
 	virtual bool stop() {
-		return !mShutdown.exchange(true);
+		if (mShutdown.exchange(true))
+			return false;
+
+		// We don't want incoming() to be called by the lower layer anymore
+		if (mLower)
+			mLower->onRecv(nullptr);
+
+		return true;
 	}
 
 	void registerIncoming() {