Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit 643a98d

Browse files
committed
Merge
2 parents a91ec31 + ae81cfa commit 643a98d

File tree

77 files changed

+888
-825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+888
-825
lines changed

src/hotspot/share/oops/klassVtable.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,26 @@ InstanceKlass* klassVtable::find_transitive_override(InstanceKlass* initialsuper
291291
int vtable_index, Handle target_loader, Symbol* target_classname, Thread * THREAD) {
292292
InstanceKlass* superk = initialsuper;
293293
while (superk != NULL && superk->super() != NULL) {
294-
InstanceKlass* supersuperklass = InstanceKlass::cast(superk->super());
295-
klassVtable ssVtable = supersuperklass->vtable();
294+
klassVtable ssVtable = (superk->super())->vtable();
296295
if (vtable_index < ssVtable.length()) {
297296
Method* super_method = ssVtable.method_at(vtable_index);
297+
// get the class holding the matching method
298+
// make sure you use that class for is_override
299+
InstanceKlass* supermethodholder = super_method->method_holder();
298300
#ifndef PRODUCT
299301
Symbol* name= target_method()->name();
300302
Symbol* signature = target_method()->signature();
301303
assert(super_method->name() == name && super_method->signature() == signature, "vtable entry name/sig mismatch");
302304
#endif
303-
if (supersuperklass->is_override(methodHandle(THREAD, super_method), target_loader, target_classname, THREAD)) {
305+
306+
if (supermethodholder->is_override(methodHandle(THREAD, super_method), target_loader, target_classname, THREAD)) {
304307
if (log_develop_is_enabled(Trace, vtables)) {
305308
ResourceMark rm(THREAD);
306309
LogTarget(Trace, vtables) lt;
307310
LogStream ls(lt);
308311
char* sig = target_method()->name_and_sig_as_C_string();
309312
ls.print("transitive overriding superclass %s with %s index %d, original flags: ",
310-
supersuperklass->internal_name(),
313+
supermethodholder->internal_name(),
311314
sig, vtable_index);
312315
super_method->print_linkage_flags(&ls);
313316
ls.print("overriders flags: ");

src/java.base/share/classes/com/sun/crypto/provider/JceKeyStore.java

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.sun.crypto.provider;
2727

2828
import sun.security.util.Debug;
29+
import sun.security.util.IOUtils;
2930

3031
import java.io.*;
3132
import java.util.*;
@@ -73,7 +74,7 @@ public final class JceKeyStore extends KeyStoreSpi {
7374
private static final class PrivateKeyEntry {
7475
Date date; // the creation date of this entry
7576
byte[] protectedKey;
76-
Certificate chain[];
77+
Certificate[] chain;
7778
};
7879

7980
// Secret key
@@ -742,51 +743,36 @@ public void engineLoad(InputStream stream, char[] password)
742743
entry.date = new Date(dis.readLong());
743744

744745
// read the private key
745-
try {
746-
entry.protectedKey = new byte[dis.readInt()];
747-
} catch (OutOfMemoryError e) {
748-
throw new IOException("Keysize too big");
749-
}
750-
dis.readFully(entry.protectedKey);
746+
entry.protectedKey = IOUtils.readExactlyNBytes(dis, dis.readInt());
751747

752748
// read the certificate chain
753749
int numOfCerts = dis.readInt();
754-
try {
755-
if (numOfCerts > 0) {
756-
entry.chain = new Certificate[numOfCerts];
757-
}
758-
} catch (OutOfMemoryError e) {
759-
throw new IOException("Too many certificates in "
760-
+ "chain");
761-
}
750+
List<Certificate> tmpCerts = new ArrayList<>();
762751
for (int j = 0; j < numOfCerts; j++) {
763752
if (xVersion == 2) {
764753
// read the certificate type, and instantiate a
765754
// certificate factory of that type (reuse
766755
// existing factory if possible)
767756
String certType = dis.readUTF();
768757
if (cfs.containsKey(certType)) {
769-
// reuse certificate factory
758+
// reuse certificate factory
770759
cf = cfs.get(certType);
771760
} else {
772-
// create new certificate factory
761+
// create new certificate factory
773762
cf = CertificateFactory.getInstance(
774763
certType);
775-
// store the certificate factory so we can
776-
// reuse it later
764+
// store the certificate factory so we can
765+
// reuse it later
777766
cfs.put(certType, cf);
778767
}
779768
}
780769
// instantiate the certificate
781-
try {
782-
encoded = new byte[dis.readInt()];
783-
} catch (OutOfMemoryError e) {
784-
throw new IOException("Certificate too big");
785-
}
786-
dis.readFully(encoded);
770+
encoded = IOUtils.readExactlyNBytes(dis, dis.readInt());
787771
bais = new ByteArrayInputStream(encoded);
788-
entry.chain[j] = cf.generateCertificate(bais);
772+
tmpCerts.add(cf.generateCertificate(bais));
789773
}
774+
entry.chain = tmpCerts.toArray(
775+
new Certificate[numOfCerts]);
790776

791777
// Add the entry to the list
792778
entries.put(alias, entry);
@@ -818,12 +804,7 @@ public void engineLoad(InputStream stream, char[] password)
818804
cfs.put(certType, cf);
819805
}
820806
}
821-
try {
822-
encoded = new byte[dis.readInt()];
823-
} catch (OutOfMemoryError e) {
824-
throw new IOException("Certificate too big");
825-
}
826-
dis.readFully(encoded);
807+
encoded = IOUtils.readExactlyNBytes(dis, dis.readInt());
827808
bais = new ByteArrayInputStream(encoded);
828809
entry.cert = cf.generateCertificate(bais);
829810

@@ -882,18 +863,14 @@ public void engineLoad(InputStream stream, char[] password)
882863
* with
883864
*/
884865
if (password != null) {
885-
byte computed[], actual[];
886-
computed = md.digest();
887-
actual = new byte[computed.length];
888-
dis.readFully(actual);
889-
for (int i = 0; i < computed.length; i++) {
890-
if (computed[i] != actual[i]) {
891-
throw new IOException(
866+
byte[] computed = md.digest();
867+
byte[] actual = IOUtils.readExactlyNBytes(dis, computed.length);
868+
if (!MessageDigest.isEqual(computed, actual)) {
869+
throw new IOException(
892870
"Keystore was tampered with, or "
893871
+ "password was incorrect",
894-
new UnrecoverableKeyException(
895-
"Password verification failed"));
896-
}
872+
new UnrecoverableKeyException(
873+
"Password verification failed"));
897874
}
898875
}
899876
} finally {

src/java.base/share/classes/java/io/ObjectInputFilter.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.function.Function;
3636

3737
import jdk.internal.access.SharedSecrets;
38+
import jdk.internal.util.StaticProperty;
3839

3940
/**
4041
* Filter classes, array lengths, and graph metrics during deserialization.
@@ -205,15 +206,17 @@ enum Status {
205206
* <p>
206207
* The filter is configured during the initialization of the {@code ObjectInputFilter.Config}
207208
* class. For example, by calling {@link #getSerialFilter() Config.getSerialFilter}.
208-
* If the system property {@systemProperty jdk.serialFilter} is defined, it is used
209-
* to configure the filter.
210-
* If the system property is not defined, and the {@link java.security.Security}
211-
* property {@code jdk.serialFilter} is defined then it is used to configure the filter.
212-
* Otherwise, the filter is not configured during initialization.
209+
* If the system property {@systemProperty jdk.serialFilter} is defined on the command line,
210+
* it is used to configure the filter.
211+
* If the system property is not defined on the command line, and the
212+
* {@link java.security.Security} property {@code jdk.serialFilter} is defined
213+
* then it is used to configure the filter.
214+
* Otherwise, the filter is not configured during initialization and
215+
* can be set with {@link #setSerialFilter(ObjectInputFilter) Config.setSerialFilter}.
216+
* Setting the {@code jdk.serialFilter} with {@link System#setProperty(String, String)
217+
* System.setProperty} <em>does not set the filter</em>.
213218
* The syntax for each property is the same as for the
214219
* {@link #createFilter(String) createFilter} method.
215-
* If a filter is not configured, it can be set with
216-
* {@link #setSerialFilter(ObjectInputFilter) Config.setSerialFilter}.
217220
*
218221
* @since 9
219222
*/
@@ -256,7 +259,7 @@ static void filterLog(System.Logger.Level level, String msg, Object... args) {
256259
static {
257260
configuredFilter = AccessController
258261
.doPrivileged((PrivilegedAction<ObjectInputFilter>) () -> {
259-
String props = System.getProperty(SERIAL_FILTER_PROPNAME);
262+
String props = StaticProperty.jdkSerialFilter();
260263
if (props == null) {
261264
props = Security.getProperty(SERIAL_FILTER_PROPNAME);
262265
}

src/java.base/share/classes/java/io/ObjectInputStream.java

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,50 @@ protected ObjectInputStream() throws IOException, SecurityException {
453453
* @throws IOException Any of the usual Input/Output related exceptions.
454454
*/
455455
public final Object readObject()
456+
throws IOException, ClassNotFoundException {
457+
return readObject(Object.class);
458+
}
459+
460+
/**
461+
* Reads a String and only a string.
462+
*
463+
* @return the String read
464+
* @throws EOFException If end of file is reached.
465+
* @throws IOException If other I/O error has occurred.
466+
*/
467+
private String readString() throws IOException {
468+
try {
469+
return (String) readObject(String.class);
470+
} catch (ClassNotFoundException cnf) {
471+
throw new IllegalStateException(cnf);
472+
}
473+
}
474+
475+
/**
476+
* Internal method to read an object from the ObjectInputStream of the expected type.
477+
* Called only from {@code readObject()} and {@code readString()}.
478+
* Only {@code Object.class} and {@code String.class} are supported.
479+
*
480+
* @param type the type expected; either Object.class or String.class
481+
* @return an object of the type
482+
* @throws IOException Any of the usual Input/Output related exceptions.
483+
* @throws ClassNotFoundException Class of a serialized object cannot be
484+
* found.
485+
*/
486+
private final Object readObject(Class<?> type)
456487
throws IOException, ClassNotFoundException
457488
{
458489
if (enableOverride) {
459490
return readObjectOverride();
460491
}
461492

493+
if (! (type == Object.class || type == String.class))
494+
throw new AssertionError("internal error");
495+
462496
// if nested read, passHandle contains handle of enclosing object
463497
int outerHandle = passHandle;
464498
try {
465-
Object obj = readObject0(false);
499+
Object obj = readObject0(type, false);
466500
handles.markDependency(outerHandle, passHandle);
467501
ClassNotFoundException ex = handles.lookupException(passHandle);
468502
if (ex != null) {
@@ -557,7 +591,7 @@ public Object readUnshared() throws IOException, ClassNotFoundException {
557591
// if nested read, passHandle contains handle of enclosing object
558592
int outerHandle = passHandle;
559593
try {
560-
Object obj = readObject0(true);
594+
Object obj = readObject0(Object.class, true);
561595
handles.markDependency(outerHandle, passHandle);
562596
ClassNotFoundException ex = handles.lookupException(passHandle);
563597
if (ex != null) {
@@ -1577,8 +1611,10 @@ private void clear() {
15771611

15781612
/**
15791613
* Underlying readObject implementation.
1614+
* @param type a type expected to be deserialized; non-null
1615+
* @param unshared true if the object can not be a reference to a shared object, otherwise false
15801616
*/
1581-
private Object readObject0(boolean unshared) throws IOException {
1617+
private Object readObject0(Class<?> type, boolean unshared) throws IOException {
15821618
boolean oldMode = bin.getBlockDataMode();
15831619
if (oldMode) {
15841620
int remain = bin.currentBlockRemaining();
@@ -1610,29 +1646,48 @@ private Object readObject0(boolean unshared) throws IOException {
16101646
return readNull();
16111647

16121648
case TC_REFERENCE:
1613-
return readHandle(unshared);
1649+
// check the type of the existing object
1650+
return type.cast(readHandle(unshared));
16141651

16151652
case TC_CLASS:
1653+
if (type == String.class) {
1654+
throw new ClassCastException("Cannot cast a class to java.lang.String");
1655+
}
16161656
return readClass(unshared);
16171657

16181658
case TC_CLASSDESC:
16191659
case TC_PROXYCLASSDESC:
1660+
if (type == String.class) {
1661+
throw new ClassCastException("Cannot cast a class to java.lang.String");
1662+
}
16201663
return readClassDesc(unshared);
16211664

16221665
case TC_STRING:
16231666
case TC_LONGSTRING:
16241667
return checkResolve(readString(unshared));
16251668

16261669
case TC_ARRAY:
1670+
if (type == String.class) {
1671+
throw new ClassCastException("Cannot cast an array to java.lang.String");
1672+
}
16271673
return checkResolve(readArray(unshared));
16281674

16291675
case TC_ENUM:
1676+
if (type == String.class) {
1677+
throw new ClassCastException("Cannot cast an enum to java.lang.String");
1678+
}
16301679
return checkResolve(readEnum(unshared));
16311680

16321681
case TC_OBJECT:
1682+
if (type == String.class) {
1683+
throw new ClassCastException("Cannot cast an object to java.lang.String");
1684+
}
16331685
return checkResolve(readOrdinaryObject(unshared));
16341686

16351687
case TC_EXCEPTION:
1688+
if (type == String.class) {
1689+
throw new ClassCastException("Cannot cast an exception to java.lang.String");
1690+
}
16361691
IOException ex = readFatalException();
16371692
throw new WriteAbortedException("writing aborted", ex);
16381693

@@ -2004,7 +2059,7 @@ private Object readArray(boolean unshared) throws IOException {
20042059

20052060
if (ccl == null) {
20062061
for (int i = 0; i < len; i++) {
2007-
readObject0(false);
2062+
readObject0(Object.class, false);
20082063
}
20092064
} else if (ccl.isPrimitive()) {
20102065
if (ccl == Integer.TYPE) {
@@ -2029,7 +2084,7 @@ private Object readArray(boolean unshared) throws IOException {
20292084
} else {
20302085
Object[] oa = (Object[]) array;
20312086
for (int i = 0; i < len; i++) {
2032-
oa[i] = readObject0(false);
2087+
oa[i] = readObject0(Object.class, false);
20332088
handles.markDependency(arrayHandle, passHandle);
20342089
}
20352090
}
@@ -2393,7 +2448,7 @@ private void skipCustomData() throws IOException {
23932448
return;
23942449

23952450
default:
2396-
readObject0(false);
2451+
readObject0(Object.class, false);
23972452
break;
23982453
}
23992454
}
@@ -2438,7 +2493,7 @@ private FieldValues defaultReadFields(Object obj, ObjectStreamClass desc)
24382493
int numPrimFields = fields.length - objVals.length;
24392494
for (int i = 0; i < objVals.length; i++) {
24402495
ObjectStreamField f = fields[numPrimFields + i];
2441-
objVals[i] = readObject0(f.isUnshared());
2496+
objVals[i] = readObject0(Object.class, f.isUnshared());
24422497
if (f.getField() != null) {
24432498
handles.markDependency(objHandle, passHandle);
24442499
}
@@ -2479,7 +2534,7 @@ private IOException readFatalException() throws IOException {
24792534
throw new InternalError();
24802535
}
24812536
clear();
2482-
return (IOException) readObject0(false);
2537+
return (IOException) readObject0(Object.class, false);
24832538
}
24842539

24852540
/**
@@ -2601,7 +2656,7 @@ void readFields() throws IOException {
26012656
int numPrimFields = fields.length - objVals.length;
26022657
for (int i = 0; i < objVals.length; i++) {
26032658
objVals[i] =
2604-
readObject0(fields[numPrimFields + i].isUnshared());
2659+
readObject0(Object.class, fields[numPrimFields + i].isUnshared());
26052660
objHandles[i] = passHandle;
26062661
}
26072662
passHandle = oldHandle;
@@ -4090,6 +4145,7 @@ private static Object cloneArray(Object array) {
40904145

40914146
static {
40924147
SharedSecrets.setJavaObjectInputStreamAccess(ObjectInputStream::checkArray);
4148+
SharedSecrets.setJavaObjectInputStreamReadString(ObjectInputStream::readString);
40934149
}
40944150

40954151
}

src/java.base/share/classes/java/net/AbstractPlainDatagramSocketImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected synchronized void create() throws SocketException {
9797
fd = new FileDescriptor();
9898
try {
9999
datagramSocketCreate();
100-
SocketCleanable.register(fd);
100+
SocketCleanable.register(fd, false);
101101
} catch (SocketException ioe) {
102102
ResourceManager.afterUdpClose();
103103
fd = null;

0 commit comments

Comments
 (0)