Browse Source

Merge pull request #669 from paullouisageneau/fix-ws-malformed-frames

Fix race condition creating malformed WebSocket frames
Paul-Louis Ageneau 3 years ago
parent
commit
4d1512c4a0
2 changed files with 4 additions and 0 deletions
  1. 2 0
      src/impl/wstransport.cpp
  2. 2 0
      src/impl/wstransport.hpp

+ 2 - 0
src/impl/wstransport.cpp

@@ -333,6 +333,8 @@ void WsTransport::recvFrame(const Frame &frame) {
 }
 }
 
 
 bool WsTransport::sendFrame(const Frame &frame) {
 bool WsTransport::sendFrame(const Frame &frame) {
+	std::lock_guard lock(mSendMutex);
+
 	PLOG_DEBUG << "WebSocket sending frame: opcode=" << int(frame.opcode)
 	PLOG_DEBUG << "WebSocket sending frame: opcode=" << int(frame.opcode)
 	           << ", length=" << frame.length;
 	           << ", length=" << frame.length;
 
 

+ 2 - 0
src/impl/wstransport.hpp

@@ -77,6 +77,8 @@ private:
 	binary mBuffer;
 	binary mBuffer;
 	binary mPartial;
 	binary mPartial;
 	Opcode mPartialOpcode;
 	Opcode mPartialOpcode;
+
+	std::mutex mSendMutex;
 };
 };
 
 
 } // namespace rtc::impl
 } // namespace rtc::impl