changeset 6653:0b84d3b434c2

8014341: Better service from Kerberos servers Summary: read incoming data safely and take care of null return value Reviewed-by: valeriep, ahgross
author weijun
date Wed, 08 May 2013 09:21:59 +0800
parents b6ab933f06e0
children 49b7500a2ca6
files src/share/classes/sun/security/krb5/KdcComm.java src/share/classes/sun/security/krb5/internal/NetClient.java
diffstat 2 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/security/krb5/KdcComm.java	Fri May 31 20:43:32 2013 +0400
+++ b/src/share/classes/sun/security/krb5/KdcComm.java	Wed May 08 09:21:59 2013 +0800
@@ -239,11 +239,15 @@
                 savedException = e;
             }
         }
-        if (ibuf == null && savedException != null) {
-            if (savedException instanceof IOException) {
-                throw (IOException) savedException;
+        if (ibuf == null) {
+            if (savedException != null) {
+                if (savedException instanceof IOException) {
+                    throw (IOException) savedException;
+                } else {
+                    throw (KrbException) savedException;
+                }
             } else {
-                throw (KrbException) savedException;
+                throw new IOException("Cannot get a KDC reply");
             }
         }
         return ibuf;
--- a/src/share/classes/sun/security/krb5/internal/NetClient.java	Fri May 31 20:43:32 2013 +0400
+++ b/src/share/classes/sun/security/krb5/internal/NetClient.java	Wed May 08 09:21:59 2013 +0800
@@ -31,6 +31,8 @@
 
 package sun.security.krb5.internal;
 
+import sun.misc.IOUtils;
+
 import java.io.*;
 import java.net.*;
 
@@ -102,17 +104,15 @@
             return null;
         }
 
-        byte data[] = new byte[len];
-        count = readFully(data, len);
-        if (count != len) {
+        try {
+            return IOUtils.readFully(in, len, true);
+        } catch (IOException ioe) {
             if (Krb5.DEBUG) {
                 System.out.println(
                     ">>>DEBUG: TCPClient could not read complete packet (" +
                     len + "/" + count + ")");
             }
             return null;
-        } else {
-            return data;
         }
     }