Skip to content
This repository
Browse code

Validated that control frames are not fragmented

  • Loading branch information...
commit ff63781b2ee6a84fa8233d17696e3e36bc42539b 1 parent 369ab5f
Martyn Loughran authored April 11, 2013
5  lib/em-websocket/framing07.rb
@@ -97,6 +97,11 @@ def process_data
97 97
             end
98 98
           end
99 99
 
  100
+          # Validate that control frames are not fragmented
  101
+          if !fin && !data_frame?(frame_type)
  102
+            raise WSProtocolError, 'Control frames must not be fragmented'
  103
+          end
  104
+
100 105
           if !fin
101 106
             debug [:moreframe, frame_type, application_data]
102 107
             @application_data_buffer << application_data
7  spec/unit/framing_spec.rb
@@ -287,5 +287,12 @@ def debug(*args); end
287 287
         @f << 'b'
288 288
       }.should raise_error(EM::WebSocket::WebSocketError, 'Continuation frame expected')
289 289
     end
  290
+
  291
+    it "should raise on non-fin control frames (control frames must not be fragmented)" do
  292
+      lambda {
  293
+        @f << 0b00001010 # Not fin, pong (opcode 10)
  294
+        @f << 0b00000000 # Length 1
  295
+      }.should raise_error(EM::WebSocket::WebSocketError, 'Control frames must not be fragmented')
  296
+    end
290 297
   end
291 298
 end

0 notes on commit ff63781

Please sign in to comment.
Something went wrong with that request. Please try again.