Diff
Modified: trunk/LayoutTests/ChangeLog (110036 => 110037)
--- trunk/LayoutTests/ChangeLog 2012-03-07 09:31:54 UTC (rev 110036)
+++ trunk/LayoutTests/ChangeLog 2012-03-07 09:39:56 UTC (rev 110037)
@@ -1,3 +1,20 @@
+2012-03-07 Kenichi Ishibashi <ba...@chromium.org>
+
+ [WebSocket] Should raise SYNTAX_ERR when message contains unpaired surrogates
+ https://bugs.webkit.org/show_bug.cgi?id=80103
+
+ Reviewed by Kent Tamura.
+
+ 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.
+
2012-03-07 Fumitoshi Ukai <u...@chromium.org>
Unreviewed, update chromium test expectations
Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/close-expected.txt (110036 => 110037)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/close-expected.txt 2012-03-07 09:31:54 UTC (rev 110036)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/close-expected.txt 2012-03-07 09:39:56 UTC (rev 110037)
@@ -1,4 +1,6 @@
CONSOLE MESSAGE: WebSocket is closed before the connection is established.
+CONSOLE MESSAGE: WebSocket close message is too long.
+CONSOLE MESSAGE: WebSocket close message is too long.
CONSOLE MESSAGE: WebSocket is closed before the connection is established.
Verify WebSocket::close behaviors.
Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason-expected.txt (0 => 110037)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason-expected.txt 2012-03-07 09:39:56 UTC (rev 110037)
@@ -0,0 +1,11 @@
+CONSOLE MESSAGE: WebSocket close message contains invalid character(s).
+Checks whether SYNTAX_ERR is thrown when attemping to close the connection with unpaired surrogates.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected.
+PASS SYNTAX_ERR was thrown.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason-expected.txt
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html (0 => 110037)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html 2012-03-07 09:39:56 UTC (rev 110037)
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/_javascript_">
+description("Checks whether SYNTAX_ERR is thrown when attemping to close the connection with unpaired surrogates.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+ layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/echo");
+
+ws._onopen_ = function()
+{
+ debug("Connected.");
+ try {
+ ws.close(1000, '\uD807');
+ testFailed('SYNTAX_ERR should be thrown.');
+ } catch(e) {
+ if (e.name == 'SYNTAX_ERR')
+ testPassed('SYNTAX_ERR was thrown.');
+ else
+ testFailed('Unexpected exception: ' + e);
+ }
+ ws.close();
+};
+
+ws._onmessage_ = function (event)
+{
+ var message = event.data;
+ testFailed("onmessage() was called. (message = \"" + message + "\")");
+};
+
+ws._onclose_ = function()
+{
+ finishJSTest();
+};
+
+</script>
+<script src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt (0 => 110037)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt 2012-03-07 09:39:56 UTC (rev 110037)
@@ -0,0 +1,11 @@
+CONSOLE MESSAGE: Websocket message contains invalid character(s).
+Checks whether SYNTAX_ERR is thrown when attemping to send unpaired surrogates.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected.
+PASS SYNTAX_ERR was thrown.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html (0 => 110037)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html 2012-03-07 09:39:56 UTC (rev 110037)
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/_javascript_">
+description("Checks whether SYNTAX_ERR is thrown when attemping to send unpaired surrogates.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+ layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/echo");
+
+ws._onopen_ = function()
+{
+ debug("Connected.");
+ try {
+ ws.send('\uD807');
+ testFailed('SYNTAX_ERR should be thrown.');
+ } catch(e) {
+ if (e.name == 'SYNTAX_ERR')
+ testPassed('SYNTAX_ERR was thrown.');
+ else
+ testFailed('Unexpected exception: ' + e);
+ }
+ ws.close();
+};
+
+ws._onmessage_ = function (event)
+{
+ var message = event.data;
+ testFailed("onmessage() was called. (message = \"" + message + "\")");
+ ws.close();
+};
+
+ws._onclose_ = function()
+{
+ finishJSTest();
+};
+
+</script>
+<script src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/workers/close-expected.txt (110036 => 110037)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/workers/close-expected.txt 2012-03-07 09:31:54 UTC (rev 110036)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/workers/close-expected.txt 2012-03-07 09:39:56 UTC (rev 110037)
@@ -1,4 +1,6 @@
CONSOLE MESSAGE: WebSocket is closed before the connection is established.
+CONSOLE MESSAGE: WebSocket close message is too long.
+CONSOLE MESSAGE: WebSocket close message is too long.
CONSOLE MESSAGE: WebSocket is closed before the connection is established.
Verify WebSocket::close behaviors in Worker.
Modified: trunk/Source/WebCore/ChangeLog (110036 => 110037)
--- trunk/Source/WebCore/ChangeLog 2012-03-07 09:31:54 UTC (rev 110036)
+++ trunk/Source/WebCore/ChangeLog 2012-03-07 09:39:56 UTC (rev 110037)
@@ -1,3 +1,21 @@
+2012-03-07 Kenichi Ishibashi <ba...@chromium.org>
+
+ [WebSocket] Should raise SYNTAX_ERR when message contains unpaired surrogates
+ https://bugs.webkit.org/show_bug.cgi?id=80103
+
+ Reviewed by Kent Tamura.
+
+ 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.
+
2012-03-07 Byungwoo Lee <bw80....@samsung.com>
[EFL] Build warning: Fix warn_unused_result warnings.
Modified: trunk/Source/WebCore/Modules/websockets/WebSocket.cpp (110036 => 110037)
--- trunk/Source/WebCore/Modules/websockets/WebSocket.cpp 2012-03-07 09:31:54 UTC (rev 110036)
+++ trunk/Source/WebCore/Modules/websockets/WebSocket.cpp 2012-03-07 09:39:56 UTC (rev 110037)
@@ -288,9 +288,14 @@
m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFramingOverhead(payloadSize));
return false;
}
- // FIXME: check message is valid utf8.
ASSERT(m_channel);
- return m_channel->send(message) == ThreadableWebSocketChannel::SendSuccess;
+ ThreadableWebSocketChannel::SendResult result = m_channel->send(message);
+ if (result == ThreadableWebSocketChannel::InvalidMessage) {
+ scriptExecutionContext()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Websocket message contains invalid character(s).");
+ ec = SYNTAX_ERR;
+ return false;
+ }
+ return result == ThreadableWebSocketChannel::SendSuccess;
}
bool WebSocket::send(ArrayBuffer* binaryData, ExceptionCode& ec)
@@ -343,11 +348,18 @@
ec = INVALID_ACCESS_ERR;
return;
}
- // FIXME: if reason contains any unpaired surrogates, raise SYNTAX_ERR.
- if (reason.utf8().length() > maxReasonSizeInBytes) {
+ CString utf8 = reason.utf8(true);
+ if (utf8.length() > maxReasonSizeInBytes) {
+ scriptExecutionContext()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "WebSocket close message is too long.");
ec = SYNTAX_ERR;
return;
}
+ // Checks whether reason is valid utf8.
+ if (utf8.isNull() && reason.length()) {
+ scriptExecutionContext()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "WebSocket close message contains invalid character(s).");
+ ec = SYNTAX_ERR;
+ return;
+ }
}
if (m_state == CLOSING || m_state == CLOSED)
Modified: trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp (110036 => 110037)
--- trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp 2012-03-07 09:31:54 UTC (rev 110036)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp 2012-03-07 09:39:56 UTC (rev 110037)
@@ -160,7 +160,9 @@
ThreadableWebSocketChannel::SendResult WebSocketChannel::send(const String& message)
{
LOG(Network, "WebSocketChannel %p send %s", this, message.utf8().data());
- CString utf8 = message.utf8();
+ CString utf8 = message.utf8(true);
+ if (utf8.isNull() && message.length())
+ return InvalidMessage;
if (m_useHixie76Protocol) {
return sendFrameHixie76(utf8.data(), utf8.length()) ? ThreadableWebSocketChannel::SendSuccess : ThreadableWebSocketChannel::SendFail;
}