This commit is contained in:
Henry Jen 2020-04-14 23:11:49 +00:00
commit 0278846eaa
91 changed files with 1073 additions and 416 deletions

View file

@ -1858,6 +1858,8 @@ public class ObjectInputStream
break;
case TC_REFERENCE:
descriptor = (ObjectStreamClass) readHandle(unshared);
// Should only reference initialized class descriptors
descriptor.checkInitialized();
break;
case TC_PROXYCLASSDESC:
descriptor = readProxyDesc(unshared);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2020, 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
@ -885,6 +885,17 @@ public class ObjectStreamClass implements Serializable {
throw new InternalError("Unexpected call when not initialized");
}
/**
* Throws InvalidClassException if not initialized.
* To be called in cases where an uninitialized class descriptor indicates
* a problem in the serialization stream.
*/
final void checkInitialized() throws InvalidClassException {
if (!initialized) {
throw new InvalidClassException("Class descriptor should be initialized");
}
}
/**
* Throws an InvalidClassException if object instances referencing this
* class descriptor should not be allowed to deserialize. This method does
@ -1150,6 +1161,10 @@ public class ObjectStreamClass implements Serializable {
} catch (IllegalAccessException ex) {
// should not occur, as access checks have been suppressed
throw new InternalError(ex);
} catch (InstantiationError err) {
var ex = new InstantiationException();
ex.initCause(err);
throw ex;
}
} else {
throw new UnsupportedOperationException();

View file

@ -116,7 +116,8 @@ class MethodType
// The remaining fields are caches of various sorts:
private @Stable MethodTypeForm form; // erased form, plus cached data about primitives
private @Stable MethodType wrapAlt; // alternative wrapped/unwrapped version
private @Stable Object wrapAlt; // alternative wrapped/unwrapped version and
// private communication for readObject and readResolve
private @Stable Invokers invokers; // cache of handy higher-order adapters
private @Stable String methodDescriptor; // cache for toMethodDescriptorString
@ -711,7 +712,7 @@ class MethodType
private static MethodType wrapWithPrims(MethodType pt) {
assert(pt.hasPrimitives());
MethodType wt = pt.wrapAlt;
MethodType wt = (MethodType)pt.wrapAlt;
if (wt == null) {
// fill in lazily
wt = MethodTypeForm.canonicalize(pt, MethodTypeForm.WRAP, MethodTypeForm.WRAP);
@ -723,7 +724,7 @@ class MethodType
private static MethodType unwrapWithNoPrims(MethodType wt) {
assert(!wt.hasPrimitives());
MethodType uwt = wt.wrapAlt;
MethodType uwt = (MethodType)wt.wrapAlt;
if (uwt == null) {
// fill in lazily
uwt = MethodTypeForm.canonicalize(wt, MethodTypeForm.UNWRAP, MethodTypeForm.UNWRAP);
@ -1248,27 +1249,18 @@ s.writeObject(this.parameterArray());
*/
@java.io.Serial
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
// Assign temporary defaults in case this object escapes
MethodType_init(void.class, NO_PTYPES);
// Assign defaults in case this object escapes
UNSAFE.putReference(this, OffsetHolder.rtypeOffset, void.class);
UNSAFE.putReference(this, OffsetHolder.ptypesOffset, NO_PTYPES);
s.defaultReadObject(); // requires serialPersistentFields to be an empty array
Class<?> returnType = (Class<?>) s.readObject();
Class<?>[] parameterArray = (Class<?>[]) s.readObject();
parameterArray = parameterArray.clone(); // make sure it is unshared
// Assign deserialized values
MethodType_init(returnType, parameterArray);
}
// Initialization of state for deserialization only
private void MethodType_init(Class<?> rtype, Class<?>[] ptypes) {
// In order to communicate these values to readResolve, we must
// store them into the implementation-specific final fields.
checkRtype(rtype);
checkPtypes(ptypes);
UNSAFE.putReference(this, OffsetHolder.rtypeOffset, rtype);
UNSAFE.putReference(this, OffsetHolder.ptypesOffset, ptypes);
// Verify all operands, and make sure ptypes is unshared
// Cache the new MethodType for readResolve
wrapAlt = new MethodType[]{MethodType.methodType(returnType, parameterArray)};
}
// Support for resetting final fields while deserializing. Implement Holder
@ -1291,12 +1283,10 @@ s.writeObject(this.parameterArray());
// Do not use a trusted path for deserialization:
// return makeImpl(rtype, ptypes, true);
// Verify all operands, and make sure ptypes is unshared:
try {
return methodType(rtype, ptypes);
} finally {
// Re-assign defaults in case this object escapes
MethodType_init(void.class, NO_PTYPES);
}
// Return a new validated MethodType for the rtype and ptypes passed from readObject.
MethodType mt = ((MethodType[])wrapAlt)[0];
wrapAlt = null;
return mt;
}
/**

View file

@ -2178,8 +2178,8 @@ class MutableBigInteger {
}
/**
* Calculate the multiplicative inverse of this mod mod, where mod is odd.
* This and mod are not changed by the calculation.
* Calculate the multiplicative inverse of this modulo mod, where the mod
* argument is odd. This and mod are not changed by the calculation.
*
* This method implements an algorithm due to Richard Schroeppel, that uses
* the same intermediate representation as Montgomery Reduction
@ -2233,8 +2233,18 @@ class MutableBigInteger {
k += trailingZeros;
}
while (c.sign < 0)
c.signedAdd(p);
if (c.compare(p) >= 0) { // c has a larger magnitude than p
MutableBigInteger remainder = c.divide(p,
new MutableBigInteger());
// The previous line ignores the sign so we copy the data back
// into c which will restore the sign as needed (and converts
// it back to a SignedMutableBigInteger)
c.copyValue(remainder);
}
if (c.sign < 0) {
c.signedAdd(p);
}
return fixup(c, p, k);
}
@ -2272,8 +2282,8 @@ class MutableBigInteger {
}
// In theory, c may be greater than p at this point (Very rare!)
while (c.compare(p) >= 0)
c.subtract(p);
if (c.compare(p) >= 0)
c = c.divide(p, new MutableBigInteger());
return c;
}

View file

@ -37,12 +37,12 @@ import java.security.PermissionCollection;
import java.security.PrivilegedAction;
import java.security.Security;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Vector;
import java.util.Map;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import sun.net.util.IPAddressUtil;
import sun.net.PortConfig;
import sun.security.util.RegisteredDomain;
@ -1349,16 +1349,13 @@ final class SocketPermissionCollection extends PermissionCollection
implements Serializable
{
// Not serialized; see serialization section at end of class
// A ConcurrentSkipListMap is used to preserve order, so that most
// recently added permissions are checked first (see JDK-4301064).
private transient ConcurrentSkipListMap<String, SocketPermission> perms;
private transient Map<String, SocketPermission> perms;
/**
* Create an empty SocketPermissions object.
*
* Create an empty SocketPermissionCollection object.
*/
public SocketPermissionCollection() {
perms = new ConcurrentSkipListMap<>(new SPCComparator());
perms = new ConcurrentHashMap<>();
}
/**
@ -1431,6 +1428,18 @@ final class SocketPermissionCollection extends PermissionCollection
int effective = 0;
int needed = desired;
var hit = perms.get(np.getName());
if (hit != null) {
// fastpath, if the host was explicitly listed
if (((needed & hit.getMask()) != 0) && hit.impliesIgnoreMask(np)) {
effective |= hit.getMask();
if ((effective & desired) == desired) {
return true;
}
needed = (desired & ~effective);
}
}
//System.out.println("implies "+np);
for (SocketPermission x : perms.values()) {
//System.out.println(" trying "+x);
@ -1512,22 +1521,9 @@ final class SocketPermissionCollection extends PermissionCollection
// Get the one we want
@SuppressWarnings("unchecked")
Vector<SocketPermission> permissions = (Vector<SocketPermission>)gfields.get("permissions", null);
perms = new ConcurrentSkipListMap<>(new SPCComparator());
perms = new ConcurrentHashMap<>(permissions.size());
for (SocketPermission sp : permissions) {
perms.put(sp.getName(), sp);
}
}
/**
* A simple comparator that orders new non-equal entries at the beginning.
*/
private static class SPCComparator implements Comparator<String> {
@Override
public int compare(String s1, String s2) {
if (s1.equals(s2)) {
return 0;
}
return -1;
}
}
}

View file

@ -80,7 +80,6 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
public $Type$Buffer slice() {
int pos = this.position();
int lim = this.limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
long addr = byteOffset(pos);
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr, segment);

View file

@ -213,7 +213,6 @@ class Direct$Type$Buffer$RW$$BO$
public $Type$Buffer slice() {
int pos = this.position();
int lim = this.limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
int off = (pos << $LG_BYTES_PER_VALUE$);
assert (off >= 0);

View file

@ -105,13 +105,15 @@ class Heap$Type$Buffer$RW$
}
public $Type$Buffer slice() {
int rem = this.remaining();
int pos = this.position();
int lim = this.limit();
int rem = (pos <= lim ? lim - pos : 0);
return new Heap$Type$Buffer$RW$(hb,
-1,
0,
rem,
rem,
this.position() + offset, segment);
pos + offset, segment);
}
@Override

View file

@ -43,12 +43,15 @@ class StringCharBuffer // package-private
}
public CharBuffer slice() {
int pos = this.position();
int lim = this.limit();
int rem = (pos <= lim ? lim - pos : 0);
return new StringCharBuffer(str,
-1,
0,
this.remaining(),
this.remaining(),
offset + this.position());
rem,
rem,
offset + pos);
}
@Override

View file

@ -428,7 +428,7 @@ public final class Scanner implements Iterator<String>, Closeable {
// here but what can we do? The final authority will be
// whatever parse method is invoked, so ultimately the
// Scanner will do the right thing
String digit = "((?i)["+radixDigits+"]|\\p{javaDigit})";
String digit = "((?i)["+radixDigits+"\\p{javaDigit}])";
String groupedNumeral = "("+non0Digit+digit+"?"+digit+"?("+
groupSeparator+digit+digit+digit+")+)";
// digit++ is the possessive form which is necessary for reducing
@ -478,7 +478,7 @@ public final class Scanner implements Iterator<String>, Closeable {
private Pattern decimalPattern;
private void buildFloatAndDecimalPattern() {
// \\p{javaDigit} may not be perfect, see above
String digit = "([0-9]|(\\p{javaDigit}))";
String digit = "(([0-9\\p{javaDigit}]))";
String exponent = "([eE][+-]?"+digit+"+)?";
String groupedNumeral = "("+non0Digit+digit+"?"+digit+"?("+
groupSeparator+digit+digit+digit+")+)";
@ -1289,25 +1289,25 @@ public final class Scanner implements Iterator<String>, Closeable {
// These must be literalized to avoid collision with regex
// metacharacters such as dot or parenthesis
groupSeparator = "\\" + dfs.getGroupingSeparator();
decimalSeparator = "\\" + dfs.getDecimalSeparator();
groupSeparator = "\\x{" + Integer.toHexString(dfs.getGroupingSeparator()) + "}";
decimalSeparator = "\\x{" + Integer.toHexString(dfs.getDecimalSeparator()) + "}";
// Quoting the nonzero length locale-specific things
// to avoid potential conflict with metacharacters
nanString = "\\Q" + dfs.getNaN() + "\\E";
infinityString = "\\Q" + dfs.getInfinity() + "\\E";
nanString = Pattern.quote(dfs.getNaN());
infinityString = Pattern.quote(dfs.getInfinity());
positivePrefix = df.getPositivePrefix();
if (!positivePrefix.isEmpty())
positivePrefix = "\\Q" + positivePrefix + "\\E";
positivePrefix = Pattern.quote(positivePrefix);
negativePrefix = df.getNegativePrefix();
if (!negativePrefix.isEmpty())
negativePrefix = "\\Q" + negativePrefix + "\\E";
negativePrefix = Pattern.quote(negativePrefix);
positiveSuffix = df.getPositiveSuffix();
if (!positiveSuffix.isEmpty())
positiveSuffix = "\\Q" + positiveSuffix + "\\E";
positiveSuffix = Pattern.quote(positiveSuffix);
negativeSuffix = df.getNegativeSuffix();
if (!negativeSuffix.isEmpty())
negativeSuffix = "\\Q" + negativeSuffix + "\\E";
negativeSuffix = Pattern.quote(negativeSuffix);
// Force rebuilding and recompilation of locale dependent
// primitive patterns