Changeset 87282 in webkit


Ignore:
Timestamp:
May 25, 2011 2:52:36 AM (13 years ago)
Author:
yutak@chromium.org
Message:

2011-05-25 Yuta Kitamura <yutak@chromium.org>

Reviewed by Kent Tamura.

WebSocket: Use fail() when WebSocketChannel has failed
https://bugs.webkit.org/show_bug.cgi?id=61353

  • http/tests/websocket/tests/frame-length-overflow-expected.txt: Added a new console message.

2011-05-25 Yuta Kitamura <yutak@chromium.org>

Reviewed by Kent Tamura.

WebSocket: Use fail() when WebSocketChannel has failed
https://bugs.webkit.org/show_bug.cgi?id=61353

An existing error message has been modified, but it is impossible
to test this message in LayoutTests because it is only shown when
memory allocation has failed, which is hard to reproduce reliably.

One new message has been added. It is covered by an existing test
http/tests/websocket/tests/frame-length-overflow.html.

There is no other change in behavior. No new tests are added.

  • websockets/WebSocketChannel.cpp: (WebCore::WebSocketChannel::fail): Do not close if we know the socket stream is already closed. This does not change the behavior, because SocketStreamBase does nothing if it is already closed. (WebCore::WebSocketChannel::didOpen): (WebCore::WebSocketChannel::didReceiveData): We need to set m_shouldDiscardReceivedData to true before calling fail(), so I moved the error message from appendToBuffer() to here. The error message was rephrased in order to improve readability. (WebCore::WebSocketChannel::appendToBuffer): Unnested the code. (WebCore::WebSocketChannel::processBuffer):
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r87280 r87282  
     12011-05-25  Yuta Kitamura  <yutak@chromium.org>
     2
     3        Reviewed by Kent Tamura.
     4
     5        WebSocket: Use fail() when WebSocketChannel has failed
     6        https://bugs.webkit.org/show_bug.cgi?id=61353
     7
     8        * http/tests/websocket/tests/frame-length-overflow-expected.txt:
     9        Added a new console message.
     10
    1112011-05-24  Pavel Podivilov  <podivilov@chromium.org>
    212
  • trunk/LayoutTests/http/tests/websocket/tests/frame-length-overflow-expected.txt

    r65135 r87282  
     1CONSOLE MESSAGE: line 0: WebSocket frame length too large
    12Make sure WebSocket does not crash and report error when it sees length overflow
    23
  • trunk/Source/WebCore/ChangeLog

    r87281 r87282  
     12011-05-25  Yuta Kitamura  <yutak@chromium.org>
     2
     3        Reviewed by Kent Tamura.
     4
     5        WebSocket: Use fail() when WebSocketChannel has failed
     6        https://bugs.webkit.org/show_bug.cgi?id=61353
     7
     8        An existing error message has been modified, but it is impossible
     9        to test this message in LayoutTests because it is only shown when
     10        memory allocation has failed, which is hard to reproduce reliably.
     11
     12        One new message has been added. It is covered by an existing test
     13        http/tests/websocket/tests/frame-length-overflow.html.
     14
     15        There is no other change in behavior. No new tests are added.
     16
     17        * websockets/WebSocketChannel.cpp:
     18        (WebCore::WebSocketChannel::fail):
     19        Do not close if we know the socket stream is already closed. This does not
     20        change the behavior, because SocketStreamBase does nothing if it is already
     21        closed.
     22        (WebCore::WebSocketChannel::didOpen):
     23        (WebCore::WebSocketChannel::didReceiveData):
     24        We need to set m_shouldDiscardReceivedData to true before calling fail(),
     25        so I moved the error message from appendToBuffer() to here.
     26        The error message was rephrased in order to improve readability.
     27        (WebCore::WebSocketChannel::appendToBuffer):
     28        Unnested the code.
     29        (WebCore::WebSocketChannel::processBuffer):
     30
    1312011-05-16  Alexander Pavlov  <apavlov@chromium.org>
    232
  • trunk/Source/WebCore/websockets/WebSocketChannel.cpp

    r87139 r87282  
    11/*
    2  * Copyright (C) 2009 Google Inc.  All rights reserved.
     2 * Copyright (C) 2011 Google Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    128128    if (m_context)
    129129        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, reason, 0, m_handshake.clientOrigin(), 0);
    130     if (m_handle)
     130    if (m_handle && !m_closed)
    131131        m_handle->close(); // Will call didClose().
    132132}
     
    165165        InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_context, m_identifier, m_handshake.clientHandshakeRequest());
    166166    CString handshakeMessage = m_handshake.clientHandshakeMessage();
    167     if (!handle->send(handshakeMessage.data(), handshakeMessage.length())) {
    168         m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error sending handshake message.", 0, m_handshake.clientOrigin(), 0);
    169         handle->close();
    170     }
     167    if (!handle->send(handshakeMessage.data(), handshakeMessage.length()))
     168        fail("Failed to send WebSocket handshake.");
    171169}
    172170
     
    209207    if (!appendToBuffer(data, len)) {
    210208        m_shouldDiscardReceivedData = true;
    211         handle->close();
     209        fail("Ran out of memory while receiving WebSocket data.");
    212210        return;
    213211    }
     
    255253    }
    256254    char* newBuffer = 0;
    257     if (tryFastMalloc(newBufferSize).getValue(newBuffer)) {
    258         if (m_buffer)
    259             memcpy(newBuffer, m_buffer, m_bufferSize);
    260         memcpy(newBuffer + m_bufferSize, data, len);
    261         fastFree(m_buffer);
    262         m_buffer = newBuffer;
    263         m_bufferSize = newBufferSize;
    264         return true;
    265     }
    266     m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "WebSocket frame (at " + String::number(static_cast<unsigned long>(newBufferSize)) + " bytes) is too long.", 0, m_handshake.clientOrigin(), 0);
    267     return false;
     255    if (!tryFastMalloc(newBufferSize).getValue(newBuffer))
     256        return false;
     257
     258    if (m_buffer)
     259        memcpy(newBuffer, m_buffer, m_bufferSize);
     260    memcpy(newBuffer + m_bufferSize, data, len);
     261    fastFree(m_buffer);
     262    m_buffer = newBuffer;
     263    m_bufferSize = newBufferSize;
     264    return true;
    268265}
    269266
     
    362359            m_shouldDiscardReceivedData = true;
    363360            m_client->didReceiveMessageError();
    364             if (!m_client)
    365                 return false;
    366             if (!m_closed)
    367                 m_handle->close();
     361            fail("WebSocket frame length too large");
    368362            return false;
    369363        }
Note: See TracChangeset for help on using the changeset viewer.