Ping and Pong messages cannot be fragmented (autobahn test: 5.1 and 5.2 Fragmentation)
This commit is contained in:
		@@ -1,6 +1,10 @@
 | 
				
			|||||||
# Changelog
 | 
					# Changelog
 | 
				
			||||||
All notable changes to this project will be documented in this file.
 | 
					All notable changes to this project will be documented in this file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## [5.1.2] - 2019-09-02
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Ping and Pong messages cannot be fragmented (autobahn test: 5.1 and 5.2 Fragmentation)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## [5.1.1] - 2019-09-01
 | 
					## [5.1.1] - 2019-09-01
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Close connections when reserved bits are used (autobahn test: 3 Reserved Bits)
 | 
					Close connections when reserved bits are used (autobahn test: 3 Reserved Bits)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,4 +21,6 @@ namespace ix
 | 
				
			|||||||
    const std::string WebSocketCloseConstants::kProtocolErrorMessage("Protocol error");
 | 
					    const std::string WebSocketCloseConstants::kProtocolErrorMessage("Protocol error");
 | 
				
			||||||
    const std::string WebSocketCloseConstants::kNoStatusCodeErrorMessage("No status code");
 | 
					    const std::string WebSocketCloseConstants::kNoStatusCodeErrorMessage("No status code");
 | 
				
			||||||
    const std::string WebSocketCloseConstants::kProtocolErrorReservedBitUsed("Reserved bit used");
 | 
					    const std::string WebSocketCloseConstants::kProtocolErrorReservedBitUsed("Reserved bit used");
 | 
				
			||||||
 | 
					    const std::string WebSocketCloseConstants::kProtocolErrorPingPayloadOversized("Ping reason control frame with payload length > 125 octets");
 | 
				
			||||||
 | 
					    const std::string WebSocketCloseConstants::kProtocolErrorCodeControlMessageFragmented("Control message fragmented");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,5 +26,7 @@ namespace ix
 | 
				
			|||||||
        static const std::string kProtocolErrorMessage;
 | 
					        static const std::string kProtocolErrorMessage;
 | 
				
			||||||
        static const std::string kNoStatusCodeErrorMessage;
 | 
					        static const std::string kNoStatusCodeErrorMessage;
 | 
				
			||||||
        static const std::string kProtocolErrorReservedBitUsed;
 | 
					        static const std::string kProtocolErrorReservedBitUsed;
 | 
				
			||||||
 | 
					        static const std::string kProtocolErrorPingPayloadOversized;
 | 
				
			||||||
 | 
					        static const std::string kProtocolErrorCodeControlMessageFragmented;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
} // namespace ix
 | 
					} // namespace ix
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -546,6 +546,17 @@ namespace ix
 | 
				
			|||||||
                return; /* Need: ws.header_size+ws.N - _rxbuf.size() */
 | 
					                return; /* Need: ws.header_size+ws.N - _rxbuf.size() */
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!ws.fin && (
 | 
				
			||||||
 | 
					                   ws.opcode == wsheader_type::PING
 | 
				
			||||||
 | 
					                || ws.opcode == wsheader_type::PONG
 | 
				
			||||||
 | 
					                || ws.opcode == wsheader_type::CLOSE
 | 
				
			||||||
 | 
					            )){
 | 
				
			||||||
 | 
					                // Cntrol messages should not be fragmented
 | 
				
			||||||
 | 
					                close(WebSocketCloseConstants::kProtocolErrorCode,
 | 
				
			||||||
 | 
					                      WebSocketCloseConstants::kProtocolErrorCodeControlMessageFragmented);
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // We got a whole message, now do something with it:
 | 
					            // We got a whole message, now do something with it:
 | 
				
			||||||
            if (
 | 
					            if (
 | 
				
			||||||
                   ws.opcode == wsheader_type::TEXT_FRAME
 | 
					                   ws.opcode == wsheader_type::TEXT_FRAME
 | 
				
			||||||
@@ -603,11 +614,9 @@ namespace ix
 | 
				
			|||||||
                // too large
 | 
					                // too large
 | 
				
			||||||
                if (pingData.size() > 125)
 | 
					                if (pingData.size() > 125)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    std::string reason("reason control frame with payload length > 125 octets");
 | 
					 | 
				
			||||||
                    // Unexpected frame type
 | 
					                    // Unexpected frame type
 | 
				
			||||||
                    close(1002,
 | 
					                    close(WebSocketCloseConstants::kProtocolErrorCode,
 | 
				
			||||||
                          reason,
 | 
					                          WebSocketCloseConstants::kProtocolErrorPingPayloadOversized);
 | 
				
			||||||
                          reason.size());
 | 
					 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1070,6 +1079,11 @@ namespace ix
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED) return;
 | 
					        if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (closeWireSize == 0)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            closeWireSize = reason.size();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            std::lock_guard<std::mutex> lock(_closeDataMutex);
 | 
					            std::lock_guard<std::mutex> lock(_closeDataMutex);
 | 
				
			||||||
            _closeCode = code;
 | 
					            _closeCode = code;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,4 +6,4 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define IX_WEBSOCKET_VERSION "5.1.1"
 | 
					#define IX_WEBSOCKET_VERSION "5.1.2"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user