rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinrongt...@apache.org
Subject [rocketmq] branch develop updated: [ISSUE#2172] Fix the issue of ArrayIndexOutOfBoundsException
Date Tue, 11 Aug 2020 02:29:59 GMT
This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 915424c  [ISSUE#2172] Fix the issue of ArrayIndexOutOfBoundsException
915424c is described below

commit 915424c2006b8d2f467f035ba5d89bb3bacaee08
Author: 陈阳 <1727611626@qq.com>
AuthorDate: Tue Aug 11 10:29:50 2020 +0800

    [ISSUE#2172] Fix the issue of ArrayIndexOutOfBoundsException
    
    Co-authored-by: fantow <hahaha>
---
 .../rocketmq/acl/plain/RemoteAddressStrategyFactory.java       | 10 +++++++---
 .../apache/rocketmq/acl/plain/RemoteAddressStrategyTest.java   | 10 ++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
b/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
index 8db0fda..0c3548e 100644
--- a/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
+++ b/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
@@ -55,11 +55,15 @@ public class RemoteAddressStrategyFactory {
                 return new MultipleRemoteAddressStrategy(AclUtils.getAddresses(remoteAddr,
last));
             } else {
                 String[] strArray = StringUtils.split(remoteAddr, ".");
-                String four = strArray[3];
-                if (!four.startsWith("{")) {
+                // However a right IP String provided by user,it always can be divided into
4 parts by '.'.
+                if (strArray.length < 4) {
+                    throw new AclException(String.format("MultipleRemoteAddressStrategy has
got a/some wrong format IP(s) ", remoteAddr));
+                }
+                String lastStr = strArray[strArray.length - 1];
+                if (!lastStr.startsWith("{")) {
                     throw new AclException(String.format("MultipleRemoteAddressStrategy netaddress
examine scope Exception netaddress", remoteAddr));
                 }
-                return new MultipleRemoteAddressStrategy(AclUtils.getAddresses(remoteAddr,
four));
+                return new MultipleRemoteAddressStrategy(AclUtils.getAddresses(remoteAddr,
lastStr));
             }
         } else if (AclUtils.isComma(remoteAddr)) {
             return new MultipleRemoteAddressStrategy(StringUtils.split(remoteAddr, ","));
diff --git a/acl/src/test/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyTest.java
b/acl/src/test/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyTest.java
index 8998dd9..87eb37b 100644
--- a/acl/src/test/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyTest.java
+++ b/acl/src/test/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyTest.java
@@ -198,6 +198,16 @@ public class RemoteAddressStrategyTest {
         remoteAddressStrategyFactory.getRemoteAddressStrategy(plainAccessResource);
         plainAccessResource.setWhiteRemoteAddress("::1,2,3}");
         remoteAddressStrategyFactory.getRemoteAddressStrategy(plainAccessResource);
+        plainAccessResource.setWhiteRemoteAddress("192.168.1.{1}");
+        remoteAddressStrategyFactory.getRemoteAddressStrategy(plainAccessResource);
+        plainAccessResource.setWhiteRemoteAddress("192.168.1.{1,2}");
+        remoteAddressStrategyFactory.getRemoteAddressStrategy(plainAccessResource);
+        plainAccessResource.setWhiteRemoteAddress("192.168.{1}");
+        remoteAddressStrategyFactory.getRemoteAddressStrategy(plainAccessResource);
+        plainAccessResource.setWhiteRemoteAddress("{192.168.1}");
+        remoteAddressStrategyFactory.getRemoteAddressStrategy(plainAccessResource);
+        plainAccessResource.setWhiteRemoteAddress("{192.168.1.1}");
+        remoteAddressStrategyFactory.getRemoteAddressStrategy(plainAccessResource);
     }
 
     private void multipleNetaddressStrategyTest(RemoteAddressStrategy remoteAddressStrategy)
{


Mime
View raw message