Changeset 109840 in webkit


Ignore:
Timestamp:
Mar 5, 2012 8:20:47 PM (12 years ago)
Author:
bashi@chromium.org
Message:

[WebSocket] Should raise SYNTAX_ERR when message contains unpaired surrogates
https://bugs.webkit.org/show_bug.cgi?id=80103

Reviewed by Kent Tamura.

Source/WebCore:

Add UTF8 validation checks for WebSocket message and close reason.

Tests: http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html

http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html

  • Modules/websockets/WebSocket.cpp:

(WebCore::WebSocket::send): Raise SYNTAX_ERR if the message is invalid.
(WebCore::WebSocket::close):Raise SYNTAX_ERR if the reason is invalid.

  • Modules/websockets/WebSocketChannel.cpp:

(WebCore::WebSocketChannel::send): Check whether message is a valid UTF8 string.

LayoutTests:

Added tests for unpaired surrogates check for WebSocket message and close reason.
Updated two expectations for close() tests because further error message is added.

  • http/tests/websocket/tests/hybi/close-expected.txt: Updated.
  • http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason-expected.txt: Added.
  • http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html: Added.
  • http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt: Added.
  • http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html: Added.
  • http/tests/websocket/tests/hybi/workers/close-expected.txt: Updated.
Location:
trunk
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r109836 r109840  
     12012-03-05  Kenichi Ishibashi  <bashi@chromium.org>
     2
     3        [WebSocket] Should raise SYNTAX_ERR when message contains unpaired surrogates
     4        https://bugs.webkit.org/show_bug.cgi?id=80103
     5
     6        Reviewed by Kent Tamura.
     7
     8        Added tests for unpaired surrogates check for WebSocket message and close reason.
     9        Updated two expectations for close() tests because further error message is added.
     10
     11        * http/tests/websocket/tests/hybi/close-expected.txt: Updated.
     12        * http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason-expected.txt: Added.
     13        * http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html: Added.
     14        * http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt: Added.
     15        * http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html: Added.
     16        * http/tests/websocket/tests/hybi/workers/close-expected.txt: Updated.
     17
    1182012-03-05  Yoshifumi Inoue  <yosin@chromium.org>
    219
  • trunk/LayoutTests/http/tests/websocket/tests/hybi/close-expected.txt

    r104803 r109840  
    11CONSOLE MESSAGE: WebSocket is closed before the connection is established.
     2CONSOLE MESSAGE: WebSocket close message is too long.
     3CONSOLE MESSAGE: WebSocket close message is too long.
    24CONSOLE MESSAGE: WebSocket is closed before the connection is established.
    35Verify WebSocket::close behaviors.
  • trunk/LayoutTests/http/tests/websocket/tests/hybi/workers/close-expected.txt

    r104803 r109840  
    11CONSOLE MESSAGE: WebSocket is closed before the connection is established.
     2CONSOLE MESSAGE: WebSocket close message is too long.
     3CONSOLE MESSAGE: WebSocket close message is too long.
    24CONSOLE MESSAGE: WebSocket is closed before the connection is established.
    35Verify WebSocket::close behaviors in Worker.
  • trunk/Source/WebCore/ChangeLog

    r109839 r109840  
     12012-03-05  Kenichi Ishibashi  <bashi@chromium.org>
     2
     3        [WebSocket] Should raise SYNTAX_ERR when message contains unpaired surrogates
     4        https://bugs.webkit.org/show_bug.cgi?id=80103
     5
     6        Reviewed by Kent Tamura.
     7
     8        Add UTF8 validation checks for WebSocket message and close reason.
     9
     10        Tests: http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html
     11               http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html
     12
     13        * Modules/websockets/WebSocket.cpp:
     14        (WebCore::WebSocket::send): Raise SYNTAX_ERR if the message is invalid.
     15        (WebCore::WebSocket::close):Raise SYNTAX_ERR if the reason is invalid.
     16        * Modules/websockets/WebSocketChannel.cpp:
     17        (WebCore::WebSocketChannel::send): Check whether message is a valid UTF8 string.
     18
    1192012-03-05  Kenneth Russell  <kbr@google.com>
    220
  • trunk/Source/WebCore/Modules/websockets/WebSocket.cpp

    r109832 r109840  
    289289        return false;
    290290    }
    291     // FIXME: check message is valid utf8.
    292291    ASSERT(m_channel);
    293     return m_channel->send(message) == ThreadableWebSocketChannel::SendSuccess;
     292    ThreadableWebSocketChannel::SendResult result = m_channel->send(message);
     293    if (result == ThreadableWebSocketChannel::InvalidMessage) {
     294        scriptExecutionContext()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Websocket message contains invalid character(s).");
     295        ec = SYNTAX_ERR;
     296        return false;
     297    }
     298    return result == ThreadableWebSocketChannel::SendSuccess;
    294299}
    295300
     
    344349            return;
    345350        }
    346         // FIXME: if reason contains any unpaired surrogates, raise SYNTAX_ERR.
    347         if (reason.utf8().length() > maxReasonSizeInBytes) {
     351        CString utf8 = reason.utf8(true);
     352        if (utf8.length() > maxReasonSizeInBytes) {
     353            scriptExecutionContext()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "WebSocket close message is too long.");
     354            ec = SYNTAX_ERR;
     355            return;
     356        }
     357        // Checks whether reason is valid utf8.
     358        if (utf8.isNull() && reason.length()) {
     359            scriptExecutionContext()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "WebSocket close message contains invalid character(s).");
    348360            ec = SYNTAX_ERR;
    349361            return;
  • trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp

    r109832 r109840  
    161161{
    162162    LOG(Network, "WebSocketChannel %p send %s", this, message.utf8().data());
    163     CString utf8 = message.utf8();
     163    CString utf8 = message.utf8(true);
     164    if (utf8.isNull() && message.length())
     165        return InvalidMessage;
    164166    if (m_useHixie76Protocol) {
    165167        return sendFrameHixie76(utf8.data(), utf8.length()) ? ThreadableWebSocketChannel::SendSuccess : ThreadableWebSocketChannel::SendFail;
Note: See TracChangeset for help on using the changeset viewer.