activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From martyntay...@apache.org
Subject activemq-artemis git commit: ARTEMIS-1482 Catch malformed SimpleString
Date Fri, 27 Oct 2017 13:12:00 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/1.x 459e5976c -> 466f5f8eb


ARTEMIS-1482 Catch malformed SimpleString


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/466f5f8e
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/466f5f8e
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/466f5f8e

Branch: refs/heads/1.x
Commit: 466f5f8ebe955250666178418783fcb8e930c73a
Parents: 459e597
Author: Martyn Taylor <mtaylor@redhat.com>
Authored: Wed Oct 25 14:19:19 2017 +0100
Committer: Martyn Taylor <mtaylor@redhat.com>
Committed: Wed Oct 25 14:23:53 2017 +0100

----------------------------------------------------------------------
 .../core/buffers/impl/ChannelBufferWrapper.java |  3 ++
 .../artemis/utils/ChannelBufferWrapperTest.java | 44 ++++++++++++++++++++
 2 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/466f5f8e/artemis-commons/src/main/java/org/apache/activemq/artemis/core/buffers/impl/ChannelBufferWrapper.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/buffers/impl/ChannelBufferWrapper.java
b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/buffers/impl/ChannelBufferWrapper.java
index 496c146..0b5fb34 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/buffers/impl/ChannelBufferWrapper.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/buffers/impl/ChannelBufferWrapper.java
@@ -89,6 +89,9 @@ public class ChannelBufferWrapper implements ActiveMQBuffer {
 
    private SimpleString readSimpleStringInternal() {
       int len = buffer.readInt();
+      if (len > buffer.readableBytes()) {
+         throw new IndexOutOfBoundsException();
+      }
       byte[] data = new byte[len];
       buffer.readBytes(data);
       return new SimpleString(data);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/466f5f8e/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ChannelBufferWrapperTest.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ChannelBufferWrapperTest.java
b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ChannelBufferWrapperTest.java
new file mode 100644
index 0000000..6ef72dc
--- /dev/null
+++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ChannelBufferWrapperTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.utils;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class ChannelBufferWrapperTest {
+
+
+   @Test
+   public void testOutOfBoundsThrownOnMalformedString() {
+      ByteBuf byteBuffer = ByteBufAllocator.DEFAULT.buffer(4);
+      byteBuffer.writeInt(100);
+
+      Exception e = null;
+      try {
+         ChannelBufferWrapper cbw = new ChannelBufferWrapper(byteBuffer);
+         cbw.readSimpleString();
+      } catch (IndexOutOfBoundsException iob) {
+         e = iob;
+      }
+      assertTrue(e instanceof IndexOutOfBoundsException);
+   }
+
+}


Mime
View raw message