merge over from jetty7
This commit is contained in:
commit
97dee04a68
|
@ -28,7 +28,6 @@ import org.eclipse.jetty.io.Buffers;
|
|||
import org.eclipse.jetty.io.EofException;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
@ -455,7 +454,6 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
|
|||
_closing=true;
|
||||
break;
|
||||
}
|
||||
|
||||
_outNIOBuffer.setPutIndex(put+_result.bytesProduced());
|
||||
}
|
||||
catch(SSLException e)
|
||||
|
|
|
@ -55,7 +55,7 @@ public class InheritedChannelConnector extends SelectChannelConnector
|
|||
LOG.warn("Unable to use System.inheritedChannel() [" +channel+ "]. Trying a new ServerSocketChannel at " + getHost() + ":" + getPort());
|
||||
|
||||
if ( _acceptChannel != null )
|
||||
_acceptChannel.configureBlocking(false);
|
||||
_acceptChannel.configureBlocking(true);
|
||||
}
|
||||
catch(NoSuchMethodError e)
|
||||
{
|
||||
|
|
|
@ -137,7 +137,11 @@ public abstract class Utf8Appendable
|
|||
// 10xxxxxx
|
||||
_bits=(_bits<<6)|(b&0x3f);
|
||||
if (--_more==0)
|
||||
{
|
||||
if (_bits>=0xD800 && _bits<=0xDFFF)
|
||||
throw new NotUtf8Exception();
|
||||
_appendable.append(new String(Character.toChars(_bits)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,25 @@ import org.junit.Test;
|
|||
|
||||
public class Utf8StringBuilderTest
|
||||
{
|
||||
@Test
|
||||
public void testInvalid()
|
||||
throws Exception
|
||||
{
|
||||
Utf8StringBuilder buffer = new Utf8StringBuilder();
|
||||
buffer.append((byte)0xED);
|
||||
buffer.append((byte)0xA0);
|
||||
try
|
||||
{
|
||||
buffer.append((byte)0x80);
|
||||
assertTrue(false);
|
||||
}
|
||||
catch(Utf8Appendable.NotUtf8Exception e)
|
||||
{
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUtfStringBuilder()
|
||||
throws Exception
|
||||
|
@ -33,7 +52,9 @@ public class Utf8StringBuilderTest
|
|||
assertEquals(source, buffer.toString());
|
||||
assertTrue(buffer.toString().endsWith("jetty"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testShort()
|
||||
throws Exception
|
||||
|
|
|
@ -42,7 +42,8 @@ import org.eclipse.jetty.websocket.WebSocket.OnTextMessage;
|
|||
public class WebSocketConnectionD13 extends AbstractConnection implements WebSocketConnection
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(WebSocketConnectionD13.class);
|
||||
|
||||
private static final boolean STRICT=true;
|
||||
|
||||
final static byte OP_CONTINUATION = 0x00;
|
||||
final static byte OP_TEXT = 0x01;
|
||||
final static byte OP_BINARY = 0x02;
|
||||
|
@ -636,6 +637,31 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
|
|||
{
|
||||
byte[] array=buffer.array();
|
||||
|
||||
if (STRICT)
|
||||
{
|
||||
if (isControlFrame(opcode) && buffer.length()>125)
|
||||
{
|
||||
_connection.close(WebSocketConnectionD13.CLOSE_PROTOCOL,"Control frame too large");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((flags&0x7)!=0)
|
||||
{
|
||||
_connection.close(WebSocketConnectionD13.CLOSE_PROTOCOL,"RSV bits set 0x"+Integer.toHexString(flags));
|
||||
return;
|
||||
}
|
||||
|
||||
if (_opcode!=-1 && opcode!=WebSocketConnectionD13.OP_CONTINUATION)
|
||||
{
|
||||
_connection.close(WebSocketConnectionD13.CLOSE_PROTOCOL,"Bad continuation"+Integer.toHexString(opcode));
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore all frames after error close
|
||||
if (_closeCode!=0 && _closeCode!=CLOSE_NORMAL && opcode!=OP_CLOSE)
|
||||
return;
|
||||
}
|
||||
|
||||
// Deliver frame if websocket is a FrameWebSocket
|
||||
if (_onFrame!=null)
|
||||
{
|
||||
|
@ -648,11 +674,17 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
|
|||
if (_onControl.onControl(opcode,array,buffer.getIndex(),buffer.length()))
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch(opcode)
|
||||
{
|
||||
case WebSocketConnectionD13.OP_CONTINUATION:
|
||||
{
|
||||
if (_opcode==-1)
|
||||
{
|
||||
_connection.close(WebSocketConnectionD13.CLOSE_PROTOCOL,"Bad Continuation");
|
||||
return;
|
||||
}
|
||||
|
||||
// If text, append to the message buffer
|
||||
if (_onTextMessage!=null && _opcode==WebSocketConnectionD13.OP_TEXT)
|
||||
{
|
||||
|
@ -673,7 +705,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
|
|||
|
||||
if (_opcode>=0 && _connection.getMaxBinaryMessageSize()>=0)
|
||||
{
|
||||
if (checkBinaryMessageSize(_aggregate.length(),buffer.length()))
|
||||
if (_aggregate!=null && checkBinaryMessageSize(_aggregate.length(),buffer.length()))
|
||||
{
|
||||
_aggregate.put(buffer);
|
||||
|
||||
|
@ -757,7 +789,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
|
|||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
case WebSocketConnectionD13.OP_BINARY:
|
||||
{
|
||||
if (_onBinaryMessage!=null && checkBinaryMessageSize(0,buffer.length()))
|
||||
{
|
||||
|
@ -779,11 +811,19 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
|
|||
_connection.close(WebSocketConnectionD13.CLOSE_POLICY_VIOLATION,"Binary frame aggregation disabled");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (STRICT)
|
||||
_connection.close(WebSocketConnectionD13.CLOSE_PROTOCOL,"Bad opcode 0x"+Integer.toHexString(opcode));
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
catch(Utf8Appendable.NotUtf8Exception notUtf8)
|
||||
{
|
||||
LOG.warn(notUtf8);
|
||||
LOG.warn("{} for {}",notUtf8,_endp);
|
||||
LOG.debug(notUtf8);
|
||||
_connection.close(WebSocketConnectionD13.CLOSE_NOT_UTF8,"Invalid UTF-8");
|
||||
|
|
|
@ -266,7 +266,7 @@ public class WebSocketParserD12 implements WebSocketParser
|
|||
if (--_bytesNeeded==0)
|
||||
{
|
||||
_bytesNeeded=(int)_length;
|
||||
if (_length>=_buffer.capacity())
|
||||
if (_length>=_buffer.capacity() && !_fakeFragments)
|
||||
{
|
||||
events++;
|
||||
_handler.close(WebSocketConnectionD12.CLOSE_BADDATA,"frame size "+_length+">"+_buffer.capacity());
|
||||
|
|
|
@ -63,7 +63,7 @@ public class WebSocketParserD13 implements WebSocketParser
|
|||
private final byte[] _mask = new byte[4];
|
||||
private int _m;
|
||||
private boolean _skip;
|
||||
private boolean _fakeFragments=true;
|
||||
private boolean _fragmentFrames=true;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
@ -89,7 +89,7 @@ public class WebSocketParserD13 implements WebSocketParser
|
|||
*/
|
||||
public boolean isFakeFragments()
|
||||
{
|
||||
return _fakeFragments;
|
||||
return _fragmentFrames;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -98,7 +98,7 @@ public class WebSocketParserD13 implements WebSocketParser
|
|||
*/
|
||||
public void setFakeFragments(boolean fakeFragments)
|
||||
{
|
||||
_fakeFragments = fakeFragments;
|
||||
_fragmentFrames = fakeFragments;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -143,7 +143,7 @@ public class WebSocketParserD13 implements WebSocketParser
|
|||
if (_buffer.space() == 0)
|
||||
{
|
||||
// Can we send a fake frame?
|
||||
if (_fakeFragments && _state==State.DATA)
|
||||
if (_fragmentFrames && _state==State.DATA)
|
||||
{
|
||||
Buffer data =_buffer.get(4*(available/4));
|
||||
_buffer.compact();
|
||||
|
@ -247,7 +247,7 @@ public class WebSocketParserD13 implements WebSocketParser
|
|||
_length = _length*0x100 + (0xff&b);
|
||||
if (--_bytesNeeded==0)
|
||||
{
|
||||
if (_length>_buffer.capacity() && !_fakeFragments)
|
||||
if (_length>_buffer.capacity() && !_fragmentFrames)
|
||||
{
|
||||
events++;
|
||||
_handler.close(WebSocketConnectionD13.CLOSE_POLICY_VIOLATION,"frame size "+_length+">"+_buffer.capacity());
|
||||
|
@ -266,7 +266,7 @@ public class WebSocketParserD13 implements WebSocketParser
|
|||
if (--_bytesNeeded==0)
|
||||
{
|
||||
_bytesNeeded=(int)_length;
|
||||
if (_length>=_buffer.capacity())
|
||||
if (_length>=_buffer.capacity() && !_fragmentFrames)
|
||||
{
|
||||
events++;
|
||||
_handler.close(WebSocketConnectionD13.CLOSE_POLICY_VIOLATION,"frame size "+_length+">"+_buffer.capacity());
|
||||
|
|
Loading…
Reference in New Issue