| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| 4 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) | 4 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| 11 * This program is distributed in the hope that it will be useful, | 11 * This program is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
| 17 * along with this program; see the file COPYING.LIB. If not, write to | 17 * along with this program; see the file COPYING.LIB. If not, write to |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 * | 20 * |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "config.h" | 23 #include "config.h" |
| 24 | 24 |
| 25 #include "modules/websockets/WebSocketFrame.h" | 25 #include "modules/websockets/WebSocketFrame.h" |
| 26 | 26 |
| 27 #include "wtf/CryptographicallyRandomNumber.h" | 27 #include "wtf/CryptographicallyRandomNumber.h" |
| 28 #include "wtf/MathExtras.h" | 28 #include "wtf/MathExtras.h" |
| 29 | 29 |
| 30 using namespace std; | |
| 31 | |
| 32 namespace WebCore { | 30 namespace WebCore { |
| 33 | 31 |
| 34 // Constants for hybi-10 frame format. | 32 // Constants for hybi-10 frame format. |
| 35 // These are bitmasks for frame composition / decomposition. | 33 // These are bitmasks for frame composition / decomposition. |
| 36 // Do not mistake these constants for the flags given to the WebSocketFrame cons
tructor. | 34 // Do not mistake these constants for the flags given to the WebSocketFrame cons
tructor. |
| 37 const unsigned char finalBit = 0x80; | 35 const unsigned char finalBit = 0x80; |
| 38 const unsigned char compressBit = 0x40; | 36 const unsigned char compressBit = 0x40; |
| 39 const unsigned char reserved2Bit = 0x20; | 37 const unsigned char reserved2Bit = 0x20; |
| 40 const unsigned char reserved3Bit = 0x10; | 38 const unsigned char reserved3Bit = 0x10; |
| 41 const unsigned char opCodeMask = 0xF; | 39 const unsigned char opCodeMask = 0xF; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 return FrameError; | 88 return FrameError; |
| 91 } | 89 } |
| 92 if (extendedPayloadLengthSize == 8 && payloadLength64 <= 0xFFFF) { | 90 if (extendedPayloadLengthSize == 8 && payloadLength64 <= 0xFFFF) { |
| 93 errorString = "The minimal number of bytes MUST be used to encode th
e length"; | 91 errorString = "The minimal number of bytes MUST be used to encode th
e length"; |
| 94 return FrameError; | 92 return FrameError; |
| 95 } | 93 } |
| 96 } | 94 } |
| 97 | 95 |
| 98 static const uint64_t maxPayloadLength = UINT64_C(0x7FFFFFFFFFFFFFFF); | 96 static const uint64_t maxPayloadLength = UINT64_C(0x7FFFFFFFFFFFFFFF); |
| 99 size_t maskingKeyLength = masked ? maskingKeyWidthInBytes : 0; | 97 size_t maskingKeyLength = masked ? maskingKeyWidthInBytes : 0; |
| 100 if (payloadLength64 > maxPayloadLength || payloadLength64 + maskingKeyLength
> numeric_limits<size_t>::max()) { | 98 if (payloadLength64 > maxPayloadLength || payloadLength64 + maskingKeyLength
> std::numeric_limits<size_t>::max()) { |
| 101 errorString = "WebSocket frame length too large: " + String::number(payl
oadLength64) + " bytes"; | 99 errorString = "WebSocket frame length too large: " + String::number(payl
oadLength64) + " bytes"; |
| 102 return FrameError; | 100 return FrameError; |
| 103 } | 101 } |
| 104 size_t payloadLength = static_cast<size_t>(payloadLength64); | 102 size_t payloadLength = static_cast<size_t>(payloadLength64); |
| 105 | 103 |
| 106 if (static_cast<size_t>(bufferEnd - p) < maskingKeyLength + payloadLength) | 104 if (static_cast<size_t>(bufferEnd - p) < maskingKeyLength + payloadLength) |
| 107 return FrameIncomplete; | 105 return FrameIncomplete; |
| 108 | 106 |
| 109 if (masked) { | 107 if (masked) { |
| 110 const char* maskingKey = p; | 108 const char* maskingKey = p; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 , compress(flags & Compress) | 189 , compress(flags & Compress) |
| 192 , reserved2(flags & Reserved2) | 190 , reserved2(flags & Reserved2) |
| 193 , reserved3(flags & Reserved3) | 191 , reserved3(flags & Reserved3) |
| 194 , masked(flags & Masked) | 192 , masked(flags & Masked) |
| 195 , payload(payload) | 193 , payload(payload) |
| 196 , payloadLength(payloadLength) | 194 , payloadLength(payloadLength) |
| 197 { | 195 { |
| 198 } | 196 } |
| 199 | 197 |
| 200 } // namespace WebCore | 198 } // namespace WebCore |
| OLD | NEW |