Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2012-08-07 12:53:33 -0400
committerJoakim Erdfelt2012-08-07 12:53:33 -0400
commitd76a5ce80ec295053a7aff9c79075a43a3572a2c (patch)
tree51ddb323332276926a00de7cbf0c31b10d424154 /jetty-websocket
parent5a77c0801a420555f309f9d86a0b73178f6383d1 (diff)
downloadorg.eclipse.jetty.project-d76a5ce80ec295053a7aff9c79075a43a3572a2c.tar.gz
org.eclipse.jetty.project-d76a5ce80ec295053a7aff9c79075a43a3572a2c.tar.xz
org.eclipse.jetty.project-d76a5ce80ec295053a7aff9c79075a43a3572a2c.zip
Fixing testcase 7.5.1 (bad utf8 close reason) handling
Diffstat (limited to 'jetty-websocket')
-rw-r--r--jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/driver/WebSocketEventDriver.java3
-rw-r--r--jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/CloseInfo.java25
-rw-r--r--jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7.java6
3 files changed, 28 insertions, 6 deletions
diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/driver/WebSocketEventDriver.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/driver/WebSocketEventDriver.java
index 22e6dd261c..14625596c1 100644
--- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/driver/WebSocketEventDriver.java
+++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/driver/WebSocketEventDriver.java
@@ -181,7 +181,8 @@ public class WebSocketEventDriver implements IncomingFrames
{
case OpCode.CLOSE:
{
- CloseInfo close = new CloseInfo(frame);
+ boolean validate = true;
+ CloseInfo close = new CloseInfo(frame,validate);
if (events.onClose != null)
{
events.onClose.call(websocket,session,close.getStatusCode(),close.getReason());
diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/CloseInfo.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/CloseInfo.java
index 62c93d6e76..0a3bda4ef9 100644
--- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/CloseInfo.java
+++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/CloseInfo.java
@@ -19,8 +19,11 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
+import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception;
+import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
+import org.eclipse.jetty.websocket.api.BadPayloadException;
import org.eclipse.jetty.websocket.api.ProtocolException;
import org.eclipse.jetty.websocket.api.StatusCode;
@@ -71,13 +74,26 @@ public class CloseInfo
// Reason
try
{
- reason = BufferUtil.toUTF8String(data);
+ Utf8StringBuilder utf = new Utf8StringBuilder();
+ utf.append(data);
+ reason = utf.toString();
+ }
+ catch (NotUtf8Exception e)
+ {
+ if (validate)
+ {
+ throw new BadPayloadException("Invalid Close Reason",e);
+ }
+ else
+ {
+ LOG.warn(e);
+ }
}
catch (RuntimeException e)
{
if (validate)
{
- throw new ProtocolException("Invalid Close Reason:",e);
+ throw new ProtocolException("Invalid Close Reason",e);
}
else
{
@@ -104,6 +120,11 @@ public class CloseInfo
this(frame.getPayload(),false);
}
+ public CloseInfo(WebSocketFrame frame, boolean validate)
+ {
+ this(frame.getPayload(),validate);
+ }
+
public ByteBuffer asByteBuffer()
{
if (statusCode != (-1))
diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7.java
index 29f25be5be..13758cc3aa 100644
--- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7.java
+++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase7.java
@@ -384,8 +384,8 @@ public class TestABCase7 extends AbstractABCase
{
ByteBuffer payload = ByteBuffer.allocate(256);
BufferUtil.clearToFill(payload);
- payload.put((byte)0xE8); // normal close
- payload.put((byte)0x03);
+ payload.put((byte)0x03); // normal close
+ payload.put((byte)0xE8);
byte invalidUtf[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5EDA080656469746564");
payload.put(invalidUtf);
BufferUtil.flipToFlush(payload,0);
@@ -397,7 +397,7 @@ public class TestABCase7 extends AbstractABCase
send.add(close);
List<WebSocketFrame> expect = new ArrayList<>();
- expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
+ expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
Fuzzer fuzzer = new Fuzzer(this);
try

Back to the top