Prechádzať zdrojové kódy

Merge pull request #338 from adematalay/FrameDataCopy

frameData is copied before passing to handlers
Dan Federman 9 rokov pred
rodič
commit
43c4a5295d
1 zmenil súbory, kde vykonal 5 pridanie a 3 odobranie
  1. 5 3
      SocketRocket/SRWebSocket.m

+ 5 - 3
SocketRocket/SRWebSocket.m

@@ -934,6 +934,8 @@ static inline BOOL closeCodeIsValid(int closeCode) {
         });
     }
     
+    //frameData will be copied before passing to handlers
+    //otherwise there can be misbehaviours when value at the pointer is changed
     switch (opcode) {
         case SROpCodeTextFrame: {
             NSString *str = [[NSString alloc] initWithData:frameData encoding:NSUTF8StringEncoding];
@@ -952,13 +954,13 @@ static inline BOOL closeCodeIsValid(int closeCode) {
             [self _handleMessage:[frameData copy]];
             break;
         case SROpCodeConnectionClose:
-            [self handleCloseWithData:frameData];
+            [self handleCloseWithData:[frameData copy]];
             break;
         case SROpCodePing:
-            [self handlePing:frameData];
+            [self handlePing:[frameData copy]];
             break;
         case SROpCodePong:
-            [self handlePong:frameData];
+            [self handlePong:[frameData copy]];
             break;
         default:
             [self _closeWithProtocolError:[NSString stringWithFormat:@"Unknown opcode %ld", (long)opcode]];