Commit 9e445d2a authored by guus's avatar guus

Make sure that encoding/decoding is strict (OF-391).

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11845 b35dd754-fafc-0310-a699-88a17e54d16e
parent f7ff07e4
...@@ -23,6 +23,7 @@ import java.net.InetSocketAddress; ...@@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder; import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.cert.Certificate; import java.security.cert.Certificate;
...@@ -98,7 +99,7 @@ public class NIOConnection implements Connection { ...@@ -98,7 +99,7 @@ public class NIOConnection implements Connection {
* Compression policy currently in use for this connection. * Compression policy currently in use for this connection.
*/ */
private CompressionPolicy compressionPolicy = CompressionPolicy.disabled; private CompressionPolicy compressionPolicy = CompressionPolicy.disabled;
private static ThreadLocal encoder = new ThreadLocalEncoder(); private static ThreadLocal<CharsetEncoder> encoder = new ThreadLocalEncoder();
/** /**
* Flag that specifies if the connection should be considered closed. Closing a NIO connection * Flag that specifies if the connection should be considered closed. Closing a NIO connection
* is an asynch operation so instead of waiting for the connection to be actually closed just * is an asynch operation so instead of waiting for the connection to be actually closed just
...@@ -252,7 +253,7 @@ public class NIOConnection implements Connection { ...@@ -252,7 +253,7 @@ public class NIOConnection implements Connection {
boolean errorDelivering = false; boolean errorDelivering = false;
try { try {
XMLWriter xmlSerializer = XMLWriter xmlSerializer =
new XMLWriter(new ByteBufferWriter(buffer, (CharsetEncoder) encoder.get()), new OutputFormat()); new XMLWriter(new ByteBufferWriter(buffer, encoder.get()), new OutputFormat());
xmlSerializer.write(packet.getElement()); xmlSerializer.write(packet.getElement());
xmlSerializer.flush(); xmlSerializer.flush();
if (flashClient) { if (flashClient) {
...@@ -439,11 +440,13 @@ public class NIOConnection implements Connection { ...@@ -439,11 +440,13 @@ public class NIOConnection implements Connection {
return super.toString() + " MINA Session: " + ioSession; return super.toString() + " MINA Session: " + ioSession;
} }
private static class ThreadLocalEncoder extends ThreadLocal { private static class ThreadLocalEncoder extends ThreadLocal<CharsetEncoder> {
@Override @Override
protected Object initialValue() { protected CharsetEncoder initialValue() {
return Charset.forName(CHARSET).newEncoder(); return Charset.forName(CHARSET).newEncoder()
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT);
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment