From b2d40b716d2fbee1a9101c43a8de9e202647644d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Andr=C3=A9=20Pearce?= Date: Fri, 18 Jan 2019 08:16:10 +0000 Subject: [PATCH 1/3] NO-JIRA Fix double check locking in ActiveMQJMSContext Double checked locking was operating on a non-volatile field this is not threadsafe, make field volatile. --- .../apache/activemq/artemis/jms/client/ActiveMQJMSContext.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQJMSContext.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQJMSContext.java index 7a6c9ef0e0..ae3ab5d75e 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQJMSContext.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQJMSContext.java @@ -58,7 +58,7 @@ public class ActiveMQJMSContext implements JMSContext { private volatile Message lastMessagesWaitingAck; private final ActiveMQConnectionForContext connection; - private Session session; + private volatile Session session; private boolean autoStart = ActiveMQJMSContext.DEFAULT_AUTO_START; private MessageProducer innerProducer; private boolean xa; @@ -91,6 +91,7 @@ public class ActiveMQJMSContext implements JMSContext { } public Session getSession() { + checkSession(); return session; } From f49d3e89dcbb961eeb34fee4edf2bd0e812a76b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Andr=C3=A9=20Pearce?= Date: Fri, 18 Jan 2019 08:20:14 +0000 Subject: [PATCH 2/3] NO-JIRA Fix possible IOE id must be less than values.length, values[id] array access might be out of bounds, as the index might be equal to the array length. --- .../apache/activemq/artemis/core/persistence/QueueStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/QueueStatus.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/QueueStatus.java index 18fa9b9d17..f4a8bdd853 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/QueueStatus.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/QueueStatus.java @@ -37,7 +37,7 @@ public enum QueueStatus { } public static QueueStatus fromID(short id) { - if (id < 0 || id > values.length) { + if (id < 0 || id >= values.length) { return null; } else { return values[id]; From 7fe45dea0b8d4c2a0e8c7de91e8eef19537d3b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Andr=C3=A9=20Pearce?= Date: Fri, 18 Jan 2019 08:33:49 +0000 Subject: [PATCH 3/3] NO-JIRA Fix possible IOE This array access might be out of bounds, as the index might be equal to the array length. --- .../org/apache/activemq/artemis/api/core/SimpleString.java | 4 ++-- .../apache/activemq/artemis/maven/ArtemisCreatePlugin.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/SimpleString.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/SimpleString.java index aabffa1874..eb3ce2e495 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/SimpleString.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/SimpleString.java @@ -342,7 +342,7 @@ public final class SimpleString implements CharSequence, Serializable, Comparabl byte high = (byte) (delim >> 8 & 0xFF); // high byte int lasPos = 0; - for (int i = 0; i < data.length; i += 2) { + for (int i = 0; i + 1 < data.length; i += 2) { if (data[i] == low && data[i + 1] == high) { byte[] bytes = new byte[i - lasPos]; System.arraycopy(data, lasPos, bytes, 0, bytes.length); @@ -439,7 +439,7 @@ public final class SimpleString implements CharSequence, Serializable, Comparabl final byte low = (byte) (c & 0xFF); // low byte final byte high = (byte) (c >> 8 & 0xFF); // high byte - for (int i = 0; i < data.length; i += 2) { + for (int i = 0; i + 1 < data.length; i += 2) { if (data[i] == low && data[i + 1] == high) { return true; } diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java index 07981d1bd0..191bb4493f 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java @@ -345,7 +345,7 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin { Charset charset = StandardCharsets.UTF_8; String content = new String(Files.readAllBytes(original), charset); - for (int i = 0; i < replacePairs.length; i += 2) { + for (int i = 0; i + 1 < replacePairs.length; i += 2) { content = content.replaceAll(replacePairs[i], replacePairs[i + 1]); } Files.write(target, content.getBytes(charset));