integer overflow, remove ununsed code and comments JDK-8145252-TLS13-branch
authorxuelei
Thu, 31 May 2018 15:37:31 -0700
branchJDK-8145252-TLS13-branch
changeset 56646 e57205a6e4ee
parent 56645 c10dbcaed048
child 56647 0d1c342d7337
integer overflow, remove ununsed code and comments
src/java.base/share/classes/sun/security/ssl/DTLSInputRecord.java
src/java.base/share/classes/sun/security/ssl/HandshakeHash.java
src/java.base/share/classes/sun/security/ssl/KeyManagerFactoryImpl.java
src/java.base/share/classes/sun/security/ssl/SSLEngineImpl.java
src/java.base/share/classes/sun/security/ssl/SSLExtension.java
src/java.base/share/classes/sun/security/ssl/SSLSecretDerivation.java
src/java.base/share/classes/sun/security/ssl/SSLTrafficKeyDerivation.java
--- a/src/java.base/share/classes/sun/security/ssl/DTLSInputRecord.java	Thu May 31 13:39:26 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/DTLSInputRecord.java	Thu May 31 15:37:31 2018 -0700
@@ -145,7 +145,7 @@
                     contentLen);
         }
 
-        int recLim = srcPos + DTLSRecord.headerSize + contentLen;
+        int recLim = Math.addExact(srcPos, DTLSRecord.headerSize + contentLen);
 
         if (this.readEpoch > recordEpoch) {
             // Reset the position of the packet buffer.
--- a/src/java.base/share/classes/sun/security/ssl/HandshakeHash.java	Thu May 31 13:39:26 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/HandshakeHash.java	Thu May 31 15:37:31 2018 -0700
@@ -86,10 +86,6 @@
         reserves.add(Arrays.copyOf(input, input.length));
     }
 
-    void receive(byte[] input, int offset, int length) {
-        reserves.add(Arrays.copyOfRange(input, offset, offset + length));
-    }
-
     void receive(ByteBuffer input, int length) {
         if (input.hasArray()) {
             int from = input.position() + input.arrayOffset();
--- a/src/java.base/share/classes/sun/security/ssl/KeyManagerFactoryImpl.java	Thu May 31 13:39:26 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/KeyManagerFactoryImpl.java	Thu May 31 15:37:31 2018 -0700
@@ -116,7 +116,6 @@
                 "Parameters must be instance of KeyStoreBuilderParameters");
             }
             if (SunJSSE.isFIPS()) {
-                // XXX should be fixed
                 throw new InvalidAlgorithmParameterException
                     ("FIPS mode: KeyStoreBuilderParameters not supported");
             }
--- a/src/java.base/share/classes/sun/security/ssl/SSLEngineImpl.java	Thu May 31 13:39:26 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/SSLEngineImpl.java	Thu May 31 15:37:31 2018 -0700
@@ -377,23 +377,16 @@
                     "source or destination buffer is null");
         }
 
-        if ((srcsOffset < 0) || (srcsLength < 0) ||
-                (srcsOffset > srcs.length - srcsLength)) {
-            throw new IndexOutOfBoundsException(
-                    "index out of bound of the source buffers");
-        }
-
         if ((dstsOffset < 0) || (dstsLength < 0) ||
                 (dstsOffset > dsts.length - dstsLength)) {
             throw new IndexOutOfBoundsException(
                     "index out of bound of the destination buffers");
         }
 
-        for (int i = srcsOffset; i < srcsOffset + srcsLength; i++) {
-            if (srcs[i] == null) {
-                throw new IllegalArgumentException(
-                        "source buffer[" + i + "] == null");
-            }
+        if ((srcsOffset < 0) || (srcsLength < 0) ||
+                (srcsOffset > srcs.length - srcsLength)) {
+            throw new IndexOutOfBoundsException(
+                    "index out of bound of the source buffers");
         }
 
         for (int i = dstsOffset; i < dstsOffset + dstsLength; i++) {
@@ -409,6 +402,13 @@
                 throw new ReadOnlyBufferException();
             }
         }
+
+        for (int i = srcsOffset; i < srcsOffset + srcsLength; i++) {
+            if (srcs[i] == null) {
+                throw new IllegalArgumentException(
+                        "source buffer[" + i + "] == null");
+            }
+        }
     }
 
     @Override
--- a/src/java.base/share/classes/sun/security/ssl/SSLExtension.java	Thu May 31 13:39:26 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/SSLExtension.java	Thu May 31 15:37:31 2018 -0700
@@ -665,16 +665,6 @@
                 extensions.remove(CH_MAX_FRAGMENT_LENGTH);
             }
 
-//            enableExtension = Utilities.getBooleanProperty(
-//                    "jdk.tls.client.enableStatusRequestExtension", true);
-//            if (!enableExtension) {
-//                extensions.remove(CH_STATUS_REQUEST);
-//                extensions.remove(CR_STATUS_REQUEST);
-//                extensions.remove(CT_STATUS_REQUEST);
-//
-//                extensions.remove(CH_STATUS_REQUEST_V2);
-//            }
-
             defaults = Collections.unmodifiableCollection(extensions);
         }
     }
@@ -691,36 +681,6 @@
                 }
             }
 
-/*
-            // Switch off SNI extention?
-            boolean enableExtension =
-                Utilities.getBooleanProperty("jsse.enableSNIExtension", true);
-            if (!enableExtension) {
-                extensions.remove(CH_SERVER_NAME);
-                extensions.remove(SH_SERVER_NAME);
-                extensions.remove(EE_SERVER_NAME);
-            }
-
-            // To switch off the max_fragment_length extension.
-            enableExtension =
-                Utilities.getBooleanProperty("jsse.enableMFLExtension", false);
-            if (!enableExtension) {
-                extensions.remove(CH_MAX_FRAGMENT_LENGTH);
-                extensions.remove(SH_MAX_FRAGMENT_LENGTH);
-                extensions.remove(EE_MAX_FRAGMENT_LENGTH);
-            }
-*/
-
-//            enableExtension = Utilities.getBooleanProperty(
-//                    "jdk.tls.server.enableStatusRequestExtension", true);
-//            if (!enableExtension) {
-//                extensions.remove(CH_STATUS_REQUEST);
-//                extensions.remove(SH_STATUS_REQUEST);
-//                extensions.remove(CR_STATUS_REQUEST);
-//                extensions.remove(CT_STATUS_REQUEST);
-//
-//                extensions.remove(SH_STATUS_REQUEST_V2);
-//            }
             defaults = Collections.unmodifiableCollection(extensions);
         }
     }
--- a/src/java.base/share/classes/sun/security/ssl/SSLSecretDerivation.java	Thu May 31 13:39:26 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/SSLSecretDerivation.java	Thu May 31 15:37:31 2018 -0700
@@ -121,6 +121,7 @@
             Record.putBytes8(m, context);
         } catch (IOException ioe) {
             // unlikely
+            throw new RuntimeException("Unexpected exception", ioe);
         }
 
         return info;
--- a/src/java.base/share/classes/sun/security/ssl/SSLTrafficKeyDerivation.java	Thu May 31 13:39:26 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/SSLTrafficKeyDerivation.java	Thu May 31 15:37:31 2018 -0700
@@ -170,6 +170,7 @@
                 Record.putInt8(m, 0x00);    // zero-length context
             } catch (IOException ioe) {
                 // unlikely
+                throw new RuntimeException("Unexpected exception", ioe);
             }
 
             return info;