提交 ffd09344 编写于 作者: W weijun

8016051: Possible ClassCastException in KdcComm

Reviewed-by: weijun
Contributed-by: NArtem Smotrakov <artem.smotrakov@oracle.com>
上级 bbc04244
...@@ -46,6 +46,7 @@ import java.util.ArrayList; ...@@ -46,6 +46,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import sun.security.krb5.internal.KRBError; import sun.security.krb5.internal.KRBError;
/** /**
...@@ -203,7 +204,6 @@ public final class KdcComm { ...@@ -203,7 +204,6 @@ public final class KdcComm {
if (obuf == null) if (obuf == null)
return null; return null;
Exception savedException = null;
Config cfg = Config.getInstance(); Config cfg = Config.getInstance();
if (realm == null) { if (realm == null) {
...@@ -218,42 +218,51 @@ public final class KdcComm { ...@@ -218,42 +218,51 @@ public final class KdcComm {
if (kdcList == null) { if (kdcList == null) {
throw new KrbException("Cannot get kdc for realm " + realm); throw new KrbException("Cannot get kdc for realm " + realm);
} }
String tempKdc = null; // may include the port number also // tempKdc may include the port number also
byte[] ibuf = null; Iterator<String> tempKdc = KdcAccessibility.list(kdcList).iterator();
for (String tmp: KdcAccessibility.list(kdcList)) { if (!tempKdc.hasNext()) {
tempKdc = tmp; throw new KrbException("Cannot get kdc for realm " + realm);
try { }
ibuf = send(obuf,tempKdc,useTCP); try {
KRBError ke = null; return sendIfPossible(obuf, tempKdc.next(), useTCP);
} catch(Exception first) {
while(tempKdc.hasNext()) {
try { try {
ke = new KRBError(ibuf); return sendIfPossible(obuf, tempKdc.next(), useTCP);
} catch (Exception e) { } catch(Exception ignore) {}
// OK
}
if (ke != null && ke.getErrorCode() ==
Krb5.KRB_ERR_RESPONSE_TOO_BIG) {
ibuf = send(obuf, tempKdc, true);
}
KdcAccessibility.removeBad(tempKdc);
break;
} catch (Exception e) {
if (DEBUG) {
System.out.println(">>> KrbKdcReq send: error trying " +
tempKdc);
e.printStackTrace(System.out);
}
KdcAccessibility.addBad(tempKdc);
savedException = e;
} }
throw first;
} }
if (ibuf == null && savedException != null) { }
if (savedException instanceof IOException) {
throw (IOException) savedException; // send the AS Request to the specified KDC
} else { // failover to using TCP if useTCP is not set and response is too big
throw (KrbException) savedException; private byte[] sendIfPossible(byte[] obuf, String tempKdc, boolean useTCP)
throws IOException, KrbException {
try {
byte[] ibuf = send(obuf, tempKdc, useTCP);
KRBError ke = null;
try {
ke = new KRBError(ibuf);
} catch (Exception e) {
// OK
}
if (ke != null && ke.getErrorCode() ==
Krb5.KRB_ERR_RESPONSE_TOO_BIG) {
ibuf = send(obuf, tempKdc, true);
}
KdcAccessibility.removeBad(tempKdc);
return ibuf;
} catch(Exception e) {
if (DEBUG) {
System.out.println(">>> KrbKdcReq send: error trying " +
tempKdc);
e.printStackTrace(System.out);
} }
KdcAccessibility.addBad(tempKdc);
throw e;
} }
return ibuf;
} }
// send the AS Request to the specified KDC // send the AS Request to the specified KDC
...@@ -496,7 +505,7 @@ public final class KdcComm { ...@@ -496,7 +505,7 @@ public final class KdcComm {
} }
// Returns a preferred KDC list by putting the bad ones at the end // Returns a preferred KDC list by putting the bad ones at the end
private static synchronized String[] list(String kdcList) { private static synchronized List<String> list(String kdcList) {
StringTokenizer st = new StringTokenizer(kdcList); StringTokenizer st = new StringTokenizer(kdcList);
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
if (badPolicy == BpType.TRY_LAST) { if (badPolicy == BpType.TRY_LAST) {
...@@ -515,7 +524,7 @@ public final class KdcComm { ...@@ -515,7 +524,7 @@ public final class KdcComm {
list.add(st.nextToken()); list.add(st.nextToken());
} }
} }
return list.toArray(new String[list.size()]); return list;
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册