Browse Source

Merge pull request #191 from paullouisageneau/fix-message-size-checks

Clarify message size checks
Paul-Louis Ageneau 4 years ago
parent
commit
6d33d19816
2 changed files with 3 additions and 3 deletions
  1. 2 0
      src/datachannel.cpp
  2. 1 3
      src/sctptransport.cpp

+ 2 - 0
src/datachannel.cpp

@@ -218,6 +218,8 @@ void DataChannel::incoming(message_ptr message) {
 
 
 	switch (message->type) {
 	switch (message->type) {
 	case Message::Control: {
 	case Message::Control: {
+		if (message->size() == 0)
+			break; // Ignore
 		auto raw = reinterpret_cast<const uint8_t *>(message->data());
 		auto raw = reinterpret_cast<const uint8_t *>(message->data());
 		switch (raw[0]) {
 		switch (raw[0]) {
 		case MESSAGE_OPEN:
 		case MESSAGE_OPEN:

+ 1 - 3
src/sctptransport.cpp

@@ -476,8 +476,6 @@ int SctpTransport::handleRecv(struct socket * /*sock*/, union sctp_sockstore /*a
                               const byte *data, size_t len, struct sctp_rcvinfo info, int flags) {
                               const byte *data, size_t len, struct sctp_rcvinfo info, int flags) {
 	try {
 	try {
 		PLOG_VERBOSE << "Handle recv, len=" << len;
 		PLOG_VERBOSE << "Handle recv, len=" << len;
-		if (!len)
-			return 0; // Ignore
 
 
 		// SCTP_FRAGMENT_INTERLEAVE does not seem to work as expected for messages > 64KB,
 		// SCTP_FRAGMENT_INTERLEAVE does not seem to work as expected for messages > 64KB,
 		// therefore partial notifications and messages need to be handled separately.
 		// therefore partial notifications and messages need to be handled separately.
@@ -497,7 +495,7 @@ int SctpTransport::handleRecv(struct socket * /*sock*/, union sctp_sockstore /*a
 			if (flags & MSG_EOR) {
 			if (flags & MSG_EOR) {
 				// Message is complete, process it
 				// Message is complete, process it
 				processData(std::move(mPartialMessage), info.rcv_sid,
 				processData(std::move(mPartialMessage), info.rcv_sid,
-				            PayloadId(htonl(info.rcv_ppid)));
+				            PayloadId(ntohl(info.rcv_ppid)));
 				mPartialMessage.clear();
 				mPartialMessage.clear();
 			}
 			}
 		}
 		}