Yiyuan GUO created HADOOP-17711: ----------------------------------- Summary: A divide by zero bug in LoadBalancingKMSClientProvider.java Key: HADOOP-17711 URL: https://issues.apache.org/jira/browse/HADOOP-17711 Project: Hadoop Common Issue Type: Bug Components: kms Affects Versions: 3.2.2 Reporter: Yiyuan GUO
In the file _kms/LoadBalancingKMSClientProvider.java_, the function _rollNewVersion_ has the following [code|https://github.com/apache/hadoop/blob/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/LoadBalancingKMSClientProvider.java#L509-#L516]: {code:java} @Override public KeyVersion rollNewVersion(final String name, final byte[] material) throws IOException { final KeyVersion newVersion = doOp(new ProviderCallable<KeyVersion>() { @Override public KeyVersion call(KMSClientProvider provider) throws IOException { return provider.rollNewVersion(name, material); } }, nextIdx(), false); ... } {code} The function _nextIdx_ uses _providers.length_ as a __ divisor: {code:java} private int nextIdx() { while (true) { int current = currentIdx.get(); int next = (current + 1) % providers.length; ...... }{code} However, _providers.length_ may be equal to zero, since the function _doOp_ explicitly checks that and throws an exception when it happens: {code:java} private <T> T doOp(ProviderCallable<T> op, int currPos, boolean isIdempotent) throws IOException { if (providers.length == 0) { throw new IOException("No providers configured !"); } ... } {code} The problem is that when _providers.length_ is 0, a divide by zero problem will happen when computing the argument for _doOp_ (inside the function _nextIdx_) __ before reaching the protection check above, causing an ArithmeticException. -- This message was sent by Atlassian Jira (v8.3.4#803005) --------------------------------------------------------------------- To unsubscribe, e-mail: common-dev-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-dev-h...@hadoop.apache.org