diff --git a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java index 7f1bec3df..4da9a5f97 100644 --- a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java @@ -309,7 +309,7 @@ final class SerializationBuilder implements Cloneable, Serializable { } // set max size once more, because current maxSize could be x64 or x2 larger than needed maxSize(constantSize); - sizeMarshaller(SizeMarshallers.constant(constantSize)); + sizeMarshaller(net.openhft.chronicle.hash.serialization.SizeMarshallers.constant(constantSize)); return this; } diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index ffcc12f14..6c0e060b8 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -32,6 +32,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.Closeable; +import java.io.EOFException; import java.io.IOException; import java.net.*; import java.nio.BufferUnderflowException; @@ -509,11 +510,44 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo } + /** + * check that the version number is valid text, + * + * @param versionNumber the version number to check + * @return true, if the version number looks correct + */ + boolean isValidVersionNumber(String versionNumber) { + + if (versionNumber.length()<=2) + return false; + + for (char c : versionNumber.toCharArray()) { + + if (c >= '0' && c <= '9') + continue; + + if (c == '.' || c == '-' || c == '_') + continue; + + if (c >= 'A' && c <= 'Z') + continue; + + if (c >= 'a' && c <= 'z') + continue; + + return false; + + } + + return true; + } + private void checkVersions(final Attached attached) { final String localVersion = BuildVersion.version(); final String remoteVersion = attached.serverVersion; + if (!remoteVersion.equals(localVersion)) { byte remoteIdentifier = attached.remoteIdentifier; LOG.warn("DIFFERENT CHRONICLE-MAP VERSIONS : " + @@ -610,10 +644,21 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo } if (attached.serverVersion == null) { - attached.serverVersion = reader.readRemoteServerVersion(); + try { + attached.serverVersion = reader.readRemoteServerVersion(); + } catch (IllegalStateException e1) { + socketChannel.close(); + } + if (attached.serverVersion == null) return; + if (!isValidVersionNumber(attached.serverVersion)) { + LOG.warn("Please check that you don't have a third party system incorrectly connecting to ChronicleMap, " + + "Closing the remote connection as Chronicle can not make sense of the remote version number received from the external connection, version="+attached.serverVersion+", Chronicle is expecting the version number to only contain '.',A-Z,a-z,0-9"); + socketChannel.close(); + } + checkVersions(attached); } diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java index 62ed81f0b..d9d8e407e 100644 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java @@ -97,6 +97,8 @@ public class TCPSocketReplicationTest { assertEquals(map1, map2); assertTrue(!map1.isEmpty()); + + Thread.sleep(9999999); } @Test