changeset 1799:299f966882e1

8189977: Improve permission portability Reviewed-by: rriggs
author igerasim
date Fri, 05 Jan 2018 20:11:29 -0800
parents 80a6c44694f2
children ffa10f8080d0
files src/share/classes/java/io/FilePermission.java src/share/classes/java/util/Hashtable.java src/share/classes/java/util/Vector.java
diffstat 3 files changed, 35 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/io/FilePermission.java	Fri Feb 16 01:37:10 2018 -0800
+++ b/src/share/classes/java/io/FilePermission.java	Fri Jan 05 20:11:29 2018 -0800
@@ -814,6 +814,8 @@
         // Get the one we want
         Vector permissions = (Vector)gfields.get("permissions", null);
         perms = new ArrayList(permissions.size());
-        perms.addAll(permissions);
+        for (Object perm : permissions) {
+            perms.add((Permission)perm);
+        }
     }
 }
--- a/src/share/classes/java/util/Hashtable.java	Fri Feb 16 01:37:10 2018 -0800
+++ b/src/share/classes/java/util/Hashtable.java	Fri Jan 05 20:11:29 2018 -0800
@@ -869,6 +869,10 @@
         if (origlength > 0 && length > origlength)
             length = origlength;
 
+        if (length < 0) { // overflow
+            length = origlength;
+        }
+
         // Check Map.Entry[].class since it's the nearest public type to
         // what we're actually creating.
         SharedSecrets.getJavaOISAccess().checkArray(s, Map.Entry[].class, length);
--- a/src/share/classes/java/util/Vector.java	Fri Feb 16 01:37:10 2018 -0800
+++ b/src/share/classes/java/util/Vector.java	Fri Jan 05 20:11:29 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,10 @@
 
 package java.util;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.StreamCorruptedException;
+
 /**
  * The {@code Vector} class implements a growable array of
  * objects. Like an array, it contains components that can be
@@ -1026,6 +1030,29 @@
     }
 
     /**
+     * Loads a {@code Vector} instance from a stream
+     * (that is, deserializes it).
+     * This method performs checks to ensure the consistency
+     * of the fields.
+     *
+     * @param in the stream
+     * @throws java.io.IOException if an I/O error occurs
+     * @throws ClassNotFoundException if the stream contains data
+     *         of a non-existing class
+     */
+    private void readObject(ObjectInputStream in)
+            throws IOException, ClassNotFoundException {
+        ObjectInputStream.GetField gfields = in.readFields();
+        int count = gfields.get("elementCount", 0);
+        Object[] data = (Object[])gfields.get("elementData", null);
+        if (count < 0 || data == null || count > data.length) {
+            throw new StreamCorruptedException("Inconsistent vector internals");
+        }
+        elementCount = count;
+        elementData = data.clone();
+    }
+
+    /**
      * Save the state of the {@code Vector} instance to a stream (that
      * is, serialize it).  This method is present merely for synchronization.
      * It just calls the default writeObject method.