Skip to content
This repository was archived by the owner on May 29, 2024. It is now read-only.

Commit 1fcfe93

Browse files
[GR-49465] Merge tag in jdk-17.0.9+9.
PullRequest: labsjdk-ce-17/123
2 parents 005f094 + 71e6a49 commit 1fcfe93

File tree

54 files changed

+1323
-351
lines changed

Some content is hidden

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

54 files changed

+1323
-351
lines changed

make/conf/version-numbers.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ DEFAULT_VERSION_CLASSFILE_MINOR=0
3939
DEFAULT_VERSION_DOCS_API_SINCE=11
4040
DEFAULT_ACCEPTABLE_BOOT_VERSIONS="16 17"
4141
DEFAULT_JDK_SOURCE_TARGET_VERSION=17
42-
DEFAULT_PROMOTED_VERSION_PRE=ea
42+
DEFAULT_PROMOTED_VERSION_PRE=

src/hotspot/share/memory/metaspace.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,13 @@ ReservedSpace Metaspace::reserve_address_space_for_compressed_classes(size_t siz
634634
// (the OS already assigned it for something else), go to the next position, wrapping
635635
// around if necessary, until we exhaust all the items.
636636
os::init_random((int)os::javaTimeNanos());
637-
r = os::random();
637+
r = ABS(os::random()) % len;
638+
assert(r >= 0, "must be");
638639
log_info(metaspace)("Randomizing compressed class space: start from %d out of %d locations",
639-
r % len, len);
640+
r, len);
640641
}
641642
for (int i = 0; i < len; i++) {
643+
assert((i + r) >= 0, "should never underflow because len is small integer");
642644
address a = list.at((i + r) % len);
643645
ReservedSpace rs(size, Metaspace::reserve_alignment(),
644646
os::vm_page_size(), (char*)a);

src/hotspot/share/opto/memnode.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,13 @@ Node* LoadNode::find_previous_arraycopy(PhaseTransform* phase, Node* ld_alloc, N
579579
Node* dest = ac->in(ArrayCopyNode::Dest);
580580

581581
if (dest == ld_base) {
582-
const TypeX *ld_offs_t = phase->type(ld_offs)->isa_intptr_t();
583-
if (ac->modifies(ld_offs_t->_lo, ld_offs_t->_hi, phase, can_see_stored_value)) {
582+
const TypeX* ld_offs_t = phase->type(ld_offs)->isa_intptr_t();
583+
assert(!ld_offs_t->empty(), "dead reference should be checked already");
584+
// Take into account vector or unsafe access size
585+
jlong ld_size_in_bytes = (jlong)memory_size();
586+
jlong offset_hi = ld_offs_t->_hi + ld_size_in_bytes - 1;
587+
offset_hi = MIN2(offset_hi, (jlong)(TypeX::MAX->_hi)); // Take care for overflow in 32-bit VM
588+
if (ac->modifies(ld_offs_t->_lo, (intptr_t)offset_hi, phase, can_see_stored_value)) {
584589
return ac;
585590
}
586591
if (!can_see_stored_value) {

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525

2626
package com.sun.crypto.provider;
2727

28+
import java.io.IOException;
29+
import java.io.InvalidObjectException;
2830
import java.lang.ref.Reference;
2931
import java.security.MessageDigest;
3032
import java.security.KeyRep;
@@ -44,7 +46,7 @@
4446
final class DESKey implements SecretKey {
4547

4648
@java.io.Serial
47-
static final long serialVersionUID = 7724971015953279128L;
49+
private static final long serialVersionUID = 7724971015953279128L;
4850

4951
private byte[] key;
5052

@@ -113,7 +115,7 @@ public int hashCode() {
113115
for (int i = 1; i < this.key.length; i++) {
114116
retval += this.key[i] * i;
115117
}
116-
return(retval ^= "des".hashCode());
118+
return(retval ^ "des".hashCode());
117119
}
118120

119121
public boolean equals(Object obj) {
@@ -134,15 +136,28 @@ public boolean equals(Object obj) {
134136
}
135137

136138
/**
137-
* readObject is called to restore the state of this key from
138-
* a stream.
139+
* Restores the state of this object from the stream.
140+
*
141+
* @param s the {@code ObjectInputStream} from which data is read
142+
* @throws IOException if an I/O error occurs
143+
* @throws ClassNotFoundException if a serialized class cannot be loaded
139144
*/
140145
@java.io.Serial
141146
private void readObject(java.io.ObjectInputStream s)
142-
throws java.io.IOException, ClassNotFoundException
147+
throws IOException, ClassNotFoundException
143148
{
144149
s.defaultReadObject();
150+
if ((key == null) || (key.length != DESKeySpec.DES_KEY_LEN)) {
151+
throw new InvalidObjectException("Wrong key size");
152+
}
145153
key = key.clone();
154+
155+
DESKeyGenerator.setParityBit(key, 0);
156+
157+
// Use the cleaner to zero the key when no longer referenced
158+
final byte[] k = key;
159+
CleanerFactory.cleaner().register(this,
160+
() -> java.util.Arrays.fill(k, (byte)0x00));
146161
}
147162

148163
/**

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525

2626
package com.sun.crypto.provider;
2727

28+
import java.io.IOException;
29+
import java.io.InvalidObjectException;
2830
import java.lang.ref.Reference;
2931
import java.security.MessageDigest;
3032
import java.security.KeyRep;
@@ -44,7 +46,7 @@
4446
final class DESedeKey implements SecretKey {
4547

4648
@java.io.Serial
47-
static final long serialVersionUID = 2463986565756745178L;
49+
private static final long serialVersionUID = 2463986565756745178L;
4850

4951
private byte[] key;
5052

@@ -112,7 +114,7 @@ public int hashCode() {
112114
for (int i = 1; i < this.key.length; i++) {
113115
retval += this.key[i] * i;
114116
}
115-
return(retval ^= "desede".hashCode());
117+
return(retval ^ "desede".hashCode());
116118
}
117119

118120
public boolean equals(Object obj) {
@@ -134,15 +136,30 @@ public boolean equals(Object obj) {
134136
}
135137

136138
/**
137-
* readObject is called to restore the state of this key from
138-
* a stream.
139+
* Restores the state of this object from the stream.
140+
*
141+
* @param s the {@code ObjectInputStream} from which data is read
142+
* @throws IOException if an I/O error occurs
143+
* @throws ClassNotFoundException if a serialized class cannot be loaded
139144
*/
140145
@java.io.Serial
141146
private void readObject(java.io.ObjectInputStream s)
142-
throws java.io.IOException, ClassNotFoundException
147+
throws IOException, ClassNotFoundException
143148
{
144149
s.defaultReadObject();
150+
if ((key == null) || (key.length != DESedeKeySpec.DES_EDE_KEY_LEN)) {
151+
throw new InvalidObjectException("Wrong key size");
152+
}
145153
key = key.clone();
154+
155+
DESKeyGenerator.setParityBit(key, 0);
156+
DESKeyGenerator.setParityBit(key, 8);
157+
DESKeyGenerator.setParityBit(key, 16);
158+
159+
// Use the cleaner to zero the key when no longer referenced
160+
final byte[] k = key;
161+
CleanerFactory.cleaner().register(this,
162+
() -> java.util.Arrays.fill(k, (byte)0x00));
146163
}
147164

148165
/**

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,16 +41,14 @@
4141
* algorithm.
4242
*
4343
* @author Jan Luehe
44-
*
45-
*
4644
* @see DHPublicKey
4745
* @see java.security.KeyAgreement
4846
*/
4947
final class DHPrivateKey implements PrivateKey,
5048
javax.crypto.interfaces.DHPrivateKey, Serializable {
5149

5250
@java.io.Serial
53-
static final long serialVersionUID = 7565477590005668886L;
51+
private static final long serialVersionUID = 7565477590005668886L;
5452

5553
// only supported version of PKCS#8 PrivateKeyInfo
5654
private static final BigInteger PKCS8_VERSION = BigInteger.ZERO;
@@ -65,10 +63,10 @@ final class DHPrivateKey implements PrivateKey,
6563
private byte[] encodedKey;
6664

6765
// the prime modulus
68-
private BigInteger p;
66+
private final BigInteger p;
6967

7068
// the base generator
71-
private BigInteger g;
69+
private final BigInteger g;
7270

7371
// the private-value length (optional)
7472
private int l;
@@ -336,4 +334,28 @@ private Object writeReplace() throws java.io.ObjectStreamException {
336334
getFormat(),
337335
encodedKey);
338336
}
337+
338+
/**
339+
* Restores the state of this object from the stream.
340+
* <p>
341+
* JDK 1.5+ objects use <code>KeyRep</code>s instead.
342+
*
343+
* @param stream the {@code ObjectInputStream} from which data is read
344+
* @throws IOException if an I/O error occurs
345+
* @throws ClassNotFoundException if a serialized class cannot be loaded
346+
*/
347+
@java.io.Serial
348+
private void readObject(ObjectInputStream stream)
349+
throws IOException, ClassNotFoundException {
350+
stream.defaultReadObject();
351+
if ((key == null) || (key.length == 0)) {
352+
throw new InvalidObjectException("key not deserializable");
353+
}
354+
this.key = key.clone();
355+
if ((encodedKey == null) || (encodedKey.length == 0)) {
356+
throw new InvalidObjectException(
357+
"encoded key not deserializable");
358+
}
359+
this.encodedKey = encodedKey.clone();
360+
}
339361
}

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,16 +40,14 @@
4040
* A public key in X.509 format for the Diffie-Hellman key agreement algorithm.
4141
*
4242
* @author Jan Luehe
43-
*
44-
*
4543
* @see DHPrivateKey
4644
* @see javax.crypto.KeyAgreement
4745
*/
4846
final class DHPublicKey implements PublicKey,
4947
javax.crypto.interfaces.DHPublicKey, Serializable {
5048

5149
@java.io.Serial
52-
static final long serialVersionUID = 7647557958927458271L;
50+
private static final long serialVersionUID = 7647557958927458271L;
5351

5452
// the public key
5553
private BigInteger y;
@@ -61,10 +59,10 @@ final class DHPublicKey implements PublicKey,
6159
private byte[] encodedKey;
6260

6361
// the prime modulus
64-
private BigInteger p;
62+
private final BigInteger p;
6563

6664
// the base generator
67-
private BigInteger g;
65+
private final BigInteger g;
6866

6967
// the private-value length (optional)
7068
private int l;
@@ -324,4 +322,28 @@ private Object writeReplace() throws java.io.ObjectStreamException {
324322
getFormat(),
325323
getEncoded());
326324
}
325+
326+
/**
327+
* Restores the state of this object from the stream.
328+
* <p>
329+
* JDK 1.5+ objects use <code>KeyRep</code>s instead.
330+
*
331+
* @param stream the {@code ObjectInputStream} from which data is read
332+
* @throws IOException if an I/O error occurs
333+
* @throws ClassNotFoundException if a serialized class cannot be loaded
334+
*/
335+
@java.io.Serial
336+
private void readObject(ObjectInputStream stream)
337+
throws IOException, ClassNotFoundException {
338+
stream.defaultReadObject();
339+
if ((key == null) || (key.length == 0)) {
340+
throw new InvalidObjectException("key not deserializable");
341+
}
342+
this.key = key.clone();
343+
if ((encodedKey == null) || (encodedKey.length == 0)) {
344+
throw new InvalidObjectException(
345+
"encoded key not deserializable");
346+
}
347+
this.encodedKey = encodedKey.clone();
348+
}
327349
}

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525

2626
package com.sun.crypto.provider;
2727

28+
import java.io.IOException;
29+
import java.io.InvalidObjectException;
2830
import java.lang.ref.Reference;
2931
import java.security.MessageDigest;
3032
import java.security.KeyRep;
@@ -45,11 +47,11 @@
4547
final class PBEKey implements SecretKey {
4648

4749
@java.io.Serial
48-
static final long serialVersionUID = -2234768909660948176L;
50+
private static final long serialVersionUID = -2234768909660948176L;
4951

5052
private byte[] key;
5153

52-
private String type;
54+
private final String type;
5355

5456
/**
5557
* Creates a PBE key from a given PBE key specification.
@@ -110,7 +112,7 @@ public int hashCode() {
110112
for (int i = 1; i < this.key.length; i++) {
111113
retval += this.key[i] * i;
112114
}
113-
return(retval ^= getAlgorithm().toLowerCase(Locale.ENGLISH).hashCode());
115+
return(retval ^ getAlgorithm().toLowerCase(Locale.ENGLISH).hashCode());
114116
}
115117

116118
public boolean equals(Object obj) {
@@ -144,15 +146,38 @@ public void destroy() {
144146
}
145147

146148
/**
147-
* readObject is called to restore the state of this key from
148-
* a stream.
149+
* Restores the state of this object from the stream.
150+
*
151+
* @param s the {@code ObjectInputStream} from which data is read
152+
* @throws IOException if an I/O error occurs
153+
* @throws ClassNotFoundException if a serialized class cannot be loaded
149154
*/
150155
@java.io.Serial
151156
private void readObject(java.io.ObjectInputStream s)
152-
throws java.io.IOException, ClassNotFoundException
157+
throws IOException, ClassNotFoundException
153158
{
154159
s.defaultReadObject();
160+
if (key == null) {
161+
throw new InvalidObjectException(
162+
"PBEKey couldn't be deserialized");
163+
}
155164
key = key.clone();
165+
166+
// Accept "\0" to signify "zero-length password with no terminator".
167+
if (!(key.length == 1 && key[0] == 0)) {
168+
for (int i = 0; i < key.length; i++) {
169+
if ((key[i] < '\u0020') || (key[i] > '\u007E')) {
170+
throw new InvalidObjectException(
171+
"PBEKey had non-ASCII chars");
172+
}
173+
}
174+
}
175+
176+
// Use the cleaner to zero the key when no longer referenced
177+
final byte[] k = this.key;
178+
CleanerFactory.cleaner().register(this,
179+
() -> Arrays.fill(k, (byte) 0x00));
180+
156181
}
157182

158183

0 commit comments

Comments
 (0)