未验证 提交 915424c2 编写于 作者: fantow111's avatar fantow111 提交者: GitHub

[ISSUE#2172] Fix the issue of ArrayIndexOutOfBoundsException

Co-authored-by: fantow <hahaha>
上级 bbfdd929
...@@ -55,11 +55,15 @@ public class RemoteAddressStrategyFactory { ...@@ -55,11 +55,15 @@ public class RemoteAddressStrategyFactory {
return new MultipleRemoteAddressStrategy(AclUtils.getAddresses(remoteAddr, last)); return new MultipleRemoteAddressStrategy(AclUtils.getAddresses(remoteAddr, last));
} else { } else {
String[] strArray = StringUtils.split(remoteAddr, "."); String[] strArray = StringUtils.split(remoteAddr, ".");
String four = strArray[3]; // However a right IP String provided by user,it always can be divided into 4 parts by '.'.
if (!four.startsWith("{")) { 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)); 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)) { } else if (AclUtils.isComma(remoteAddr)) {
return new MultipleRemoteAddressStrategy(StringUtils.split(remoteAddr, ",")); return new MultipleRemoteAddressStrategy(StringUtils.split(remoteAddr, ","));
......
...@@ -198,6 +198,16 @@ public class RemoteAddressStrategyTest { ...@@ -198,6 +198,16 @@ public class RemoteAddressStrategyTest {
remoteAddressStrategyFactory.getRemoteAddressStrategy(plainAccessResource); remoteAddressStrategyFactory.getRemoteAddressStrategy(plainAccessResource);
plainAccessResource.setWhiteRemoteAddress("::1,2,3}"); plainAccessResource.setWhiteRemoteAddress("::1,2,3}");
remoteAddressStrategyFactory.getRemoteAddressStrategy(plainAccessResource); 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) { private void multipleNetaddressStrategyTest(RemoteAddressStrategy remoteAddressStrategy) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册