Skip to content

Commit da461be

Browse files
committed
Merge tag 'jdk-17.0.17+10' into v0.56.0-release
Signed-off-by: Peter Shipton <[email protected]>
2 parents a2ed854 + 193fcd1 commit da461be

File tree

11 files changed

+185
-30
lines changed

11 files changed

+185
-30
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/java.base/share/classes/sun/security/util/DerValue.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,22 @@ public String getUniversalString() throws IOException {
852852
return readStringInternal(tag_UniversalString, new UTF_32BE());
853853
}
854854

855+
/**
856+
* Checks that the BMPString does not contain any surrogate characters,
857+
* which are outside the Basic Multilingual Plane.
858+
*
859+
* @throws IOException if illegal characters are detected
860+
*/
861+
public void validateBMPString() throws IOException {
862+
String bmpString = getBMPString();
863+
for (int i = 0; i < bmpString.length(); i++) {
864+
if (Character.isSurrogate(bmpString.charAt(i))) {
865+
throw new IOException(
866+
"Illegal character in BMPString, index: " + i);
867+
}
868+
}
869+
}
870+
855871
/**
856872
* Reads the ASN.1 NULL value
857873
*/

src/java.base/share/classes/sun/security/x509/AVA.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2025, 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
@@ -28,10 +28,13 @@
2828
import java.io.ByteArrayOutputStream;
2929
import java.io.IOException;
3030
import java.io.Reader;
31+
import java.nio.charset.Charset;
3132
import java.text.Normalizer;
3233
import java.util.*;
3334

35+
import static java.nio.charset.StandardCharsets.ISO_8859_1;
3436
import static java.nio.charset.StandardCharsets.UTF_8;
37+
import static java.nio.charset.StandardCharsets.UTF_16BE;
3538

3639
import sun.security.action.GetBooleanAction;
3740
import sun.security.util.*;
@@ -594,6 +597,10 @@ private static boolean trailingSpace(Reader in) throws IOException {
594597
throw new IOException("AVA, extra bytes = "
595598
+ derval.data.available());
596599
}
600+
601+
if (value.tag == DerValue.tag_BMPString) {
602+
value.validateBMPString();
603+
}
597604
}
598605

599606
AVA(DerInputStream in) throws IOException {
@@ -735,7 +742,7 @@ public String toRFC2253String(Map<String, String> oidMap) {
735742
*/
736743
String valStr = null;
737744
try {
738-
valStr = new String(value.getDataBytes(), UTF_8);
745+
valStr = new String(value.getDataBytes(), getCharset(value, false));
739746
} catch (IOException ie) {
740747
throw new IllegalArgumentException("DER Value conversion");
741748
}
@@ -870,7 +877,7 @@ public String toRFC2253CanonicalString() {
870877
*/
871878
String valStr = null;
872879
try {
873-
valStr = new String(value.getDataBytes(), UTF_8);
880+
valStr = new String(value.getDataBytes(), getCharset(value, true));
874881
} catch (IOException ie) {
875882
throw new IllegalArgumentException("DER Value conversion");
876883
}
@@ -977,6 +984,39 @@ private static boolean isDerString(DerValue value, boolean canonical) {
977984
}
978985
}
979986

987+
/*
988+
* Returns the charset that should be used to decode each DN string type.
989+
*
990+
* This method ensures that multi-byte (UTF8String and BMPString) types
991+
* are decoded using the correct charset and the String forms represent
992+
* the correct characters. For 8-bit ASCII-based types (PrintableString
993+
* and IA5String), we return ISO_8859_1 rather than ASCII, so that the
994+
* complete range of characters can be represented, as many certificates
995+
* do not comply with the Internationalized Domain Name ACE format.
996+
*
997+
* NOTE: this method only supports DirectoryStrings of the types returned
998+
* by isDerString().
999+
*/
1000+
private static Charset getCharset(DerValue value, boolean canonical) {
1001+
if (canonical) {
1002+
return switch (value.tag) {
1003+
case DerValue.tag_PrintableString -> ISO_8859_1;
1004+
case DerValue.tag_UTF8String -> UTF_8;
1005+
default -> throw new Error("unexpected tag: " + value.tag);
1006+
};
1007+
}
1008+
1009+
return switch (value.tag) {
1010+
case DerValue.tag_PrintableString,
1011+
DerValue.tag_T61String,
1012+
DerValue.tag_IA5String,
1013+
DerValue.tag_GeneralString -> ISO_8859_1;
1014+
case DerValue.tag_BMPString -> UTF_16BE;
1015+
case DerValue.tag_UTF8String -> UTF_8;
1016+
default -> throw new Error("unexpected tag: " + value.tag);
1017+
};
1018+
}
1019+
9801020
boolean hasRFC2253Keyword() {
9811021
return AVAKeyword.hasKeyword(oid, RFC2253);
9821022
}

src/java.base/share/native/libverify/check_code.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ static jboolean is_superclass(context_type *, fullinfo_type);
395395

396396
static void initialize_exception_table(context_type *);
397397
static int instruction_length(unsigned char *iptr, unsigned char *end);
398-
static jboolean isLegalTarget(context_type *, int offset);
398+
static jboolean isLegalOffset(context_type *, int bci, int offset);
399+
static jboolean isLegalTarget(context_type *, int target);
399400
static void verify_constant_pool_type(context_type *, int, unsigned);
400401

401402
static void initialize_dataflow(context_type *);
@@ -1154,9 +1155,9 @@ verify_opcode_operands(context_type *context, unsigned int inumber, int offset)
11541155
case JVM_OPC_goto: {
11551156
/* Set the ->operand to be the instruction number of the target. */
11561157
int jump = (((signed char)(code[offset+1])) << 8) + code[offset+2];
1157-
int target = offset + jump;
1158-
if (!isLegalTarget(context, target))
1158+
if (!isLegalOffset(context, offset, jump))
11591159
CCerror(context, "Illegal target of jump or branch");
1160+
int target = offset + jump;
11601161
this_idata->operand.i = code_data[target];
11611162
break;
11621163
}
@@ -1170,9 +1171,9 @@ verify_opcode_operands(context_type *context, unsigned int inumber, int offset)
11701171
int jump = (((signed char)(code[offset+1])) << 24) +
11711172
(code[offset+2] << 16) + (code[offset+3] << 8) +
11721173
(code[offset + 4]);
1173-
int target = offset + jump;
1174-
if (!isLegalTarget(context, target))
1174+
if (!isLegalOffset(context, offset, jump))
11751175
CCerror(context, "Illegal target of jump or branch");
1176+
int target = offset + jump;
11761177
this_idata->operand.i = code_data[target];
11771178
break;
11781179
}
@@ -1211,13 +1212,16 @@ verify_opcode_operands(context_type *context, unsigned int inumber, int offset)
12111212
}
12121213
}
12131214
saved_operand = NEW(int, keys + 2);
1214-
if (!isLegalTarget(context, offset + _ck_ntohl(lpc[0])))
1215+
int jump = _ck_ntohl(lpc[0]);
1216+
if (!isLegalOffset(context, offset, jump))
12151217
CCerror(context, "Illegal default target in switch");
1216-
saved_operand[keys + 1] = code_data[offset + _ck_ntohl(lpc[0])];
1218+
int target = offset + jump;
1219+
saved_operand[keys + 1] = code_data[target];
12171220
for (k = keys, lptr = &lpc[3]; --k >= 0; lptr += delta) {
1218-
int target = offset + _ck_ntohl(lptr[0]);
1219-
if (!isLegalTarget(context, target))
1221+
jump = _ck_ntohl(lptr[0]);
1222+
if (!isLegalOffset(context, offset, jump))
12201223
CCerror(context, "Illegal branch in tableswitch");
1224+
target = offset + jump;
12211225
saved_operand[k + 1] = code_data[target];
12221226
}
12231227
saved_operand[0] = keys + 1; /* number of successors */
@@ -1746,11 +1750,24 @@ static int instruction_length(unsigned char *iptr, unsigned char *end)
17461750

17471751
/* Given the target of a branch, make sure that it's a legal target. */
17481752
static jboolean
1749-
isLegalTarget(context_type *context, int offset)
1753+
isLegalTarget(context_type *context, int target)
1754+
{
1755+
int code_length = context->code_length;
1756+
int *code_data = context->code_data;
1757+
return (target >= 0 && target < code_length && code_data[target] >= 0);
1758+
}
1759+
1760+
/* Given a bci and offset, make sure the offset is valid and the target is legal */
1761+
static jboolean
1762+
isLegalOffset(context_type *context, int bci, int offset)
17501763
{
17511764
int code_length = context->code_length;
17521765
int *code_data = context->code_data;
1753-
return (offset >= 0 && offset < code_length && code_data[offset] >= 0);
1766+
int max_offset = 65535; // JVMS 4.11
1767+
int min_offset = -65535;
1768+
if (offset < min_offset || offset > max_offset) return JNI_FALSE;
1769+
int target = bci + offset;
1770+
return (target >= 0 && target < code_length && code_data[target] >= 0);
17541771
}
17551772

17561773

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/DocumentBuilderFactoryImpl.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import com.sun.org.apache.xerces.internal.parsers.DOMParser;
2424
import com.sun.org.apache.xerces.internal.util.SAXMessageFormatter;
25-
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
2625
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
2726
import java.util.HashMap;
2827
import java.util.Map;
@@ -32,14 +31,15 @@
3231
import javax.xml.parsers.ParserConfigurationException;
3332
import javax.xml.validation.Schema;
3433
import jdk.xml.internal.JdkProperty;
34+
import jdk.xml.internal.XMLSecurityManager;
3535
import org.xml.sax.SAXException;
3636
import org.xml.sax.SAXNotRecognizedException;
3737
import org.xml.sax.SAXNotSupportedException;
3838

3939
/**
4040
* @author Rajiv Mordani
4141
* @author Edwin Goei
42-
* @LastModified: May 2021
42+
* @LastModified: June 2025
4343
*/
4444
public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
4545
/** These are DocumentBuilderFactory attributes not DOM attributes */
@@ -54,8 +54,26 @@ public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
5454
private boolean fSecureProcess = true;
5555

5656
// used to verify attributes
57-
XMLSecurityManager fSecurityManager = new XMLSecurityManager(true);
58-
XMLSecurityPropertyManager fSecurityPropertyMgr = new XMLSecurityPropertyManager();
57+
XMLSecurityManager fSecurityManager;
58+
XMLSecurityPropertyManager fSecurityPropertyMgr;
59+
60+
/**
61+
* Creates a new {@code DocumentBuilderFactory} instance.
62+
*/
63+
public DocumentBuilderFactoryImpl() {
64+
this(null, null);
65+
}
66+
67+
/**
68+
* Creates a new {@code DocumentBuilderFactory} instance with a {@code XMLSecurityManager}
69+
* and {@code XMLSecurityPropertyManager}.
70+
* @param xsm the {@code XMLSecurityManager}
71+
* @param xspm the {@code XMLSecurityPropertyManager}
72+
*/
73+
public DocumentBuilderFactoryImpl(XMLSecurityManager xsm, XMLSecurityPropertyManager xspm) {
74+
fSecurityManager = (xsm == null) ? new XMLSecurityManager(true) : xsm;
75+
fSecurityPropertyMgr = (xspm == null) ? new XMLSecurityPropertyManager() : xspm;
76+
}
5977

6078
/**
6179
* Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder}

src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.sun.org.apache.xpath.internal.jaxp;
2222

2323
import com.sun.org.apache.xalan.internal.res.XSLMessages;
24+
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
2425
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
2526
import javax.xml.XMLConstants;
2627
import javax.xml.xpath.XPathFactory;
@@ -37,7 +38,7 @@
3738
*
3839
* @author Ramesh Mandava
3940
*
40-
* @LastModified: Jan 2022
41+
* @LastModified: June 2025
4142
*/
4243
public class XPathFactoryImpl extends XPathFactory {
4344

@@ -74,6 +75,7 @@ public class XPathFactoryImpl extends XPathFactory {
7475
* The XML security manager
7576
*/
7677
private XMLSecurityManager _xmlSecMgr;
78+
private XMLSecurityPropertyManager _xmlSecPropMgr;
7779

7880
/**
7981
* javax.xml.xpath.XPathFactory implementation.
@@ -86,6 +88,7 @@ public XPathFactoryImpl() {
8688
}
8789
_featureManager = new JdkXmlFeatures(!_isNotSecureProcessing);
8890
_xmlSecMgr = new XMLSecurityManager(true);
91+
_xmlSecPropMgr = new XMLSecurityPropertyManager();
8992
}
9093

9194
/**
@@ -135,7 +138,7 @@ public boolean isObjectModelSupported(String objectModel) {
135138
*/
136139
public javax.xml.xpath.XPath newXPath() {
137140
return new XPathImpl(xPathVariableResolver, xPathFunctionResolver,
138-
!_isNotSecureProcessing, _featureManager, _xmlSecMgr);
141+
!_isNotSecureProcessing, _featureManager, _xmlSecMgr, _xmlSecPropMgr);
139142
}
140143

141144
/**
@@ -189,6 +192,7 @@ public void setFeature(String name, boolean value)
189192
if (value && _featureManager != null) {
190193
_featureManager.setFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION,
191194
JdkProperty.State.FSP, false);
195+
_xmlSecMgr.setSecureProcessing(value);
192196
}
193197

194198
// all done processing feature

src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package com.sun.org.apache.xpath.internal.jaxp;
2222

23+
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
2324
import com.sun.org.apache.xpath.internal.*;
2425
import com.sun.org.apache.xpath.internal.objects.XObject;
2526
import javax.xml.namespace.NamespaceContext;
@@ -47,7 +48,7 @@
4748
* New methods: evaluateExpression
4849
* Refactored to share code with XPathExpressionImpl.
4950
*
50-
* @LastModified: Jan 2022
51+
* @LastModified: June 2025
5152
*/
5253
public class XPathImpl extends XPathImplUtil implements javax.xml.xpath.XPath {
5354

@@ -57,19 +58,21 @@ public class XPathImpl extends XPathImplUtil implements javax.xml.xpath.XPath {
5758
private NamespaceContext namespaceContext=null;
5859

5960
XPathImpl(XPathVariableResolver vr, XPathFunctionResolver fr) {
60-
this(vr, fr, false, new JdkXmlFeatures(false), new XMLSecurityManager(true));
61+
this(vr, fr, false, new JdkXmlFeatures(false), new XMLSecurityManager(true),
62+
new XMLSecurityPropertyManager());
6163
}
6264

6365
XPathImpl(XPathVariableResolver vr, XPathFunctionResolver fr,
6466
boolean featureSecureProcessing, JdkXmlFeatures featureManager,
65-
XMLSecurityManager xmlSecMgr) {
67+
XMLSecurityManager xmlSecMgr, XMLSecurityPropertyManager xmlSecPropMgr) {
6668
this.origVariableResolver = this.variableResolver = vr;
6769
this.origFunctionResolver = this.functionResolver = fr;
6870
this.featureSecureProcessing = featureSecureProcessing;
6971
this.featureManager = featureManager;
7072
overrideDefaultParser = featureManager.getFeature(
7173
JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
7274
this.xmlSecMgr = xmlSecMgr;
75+
this.xmlSecPropMgr = xmlSecPropMgr;
7376
}
7477

7578

src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImplUtil.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import com.sun.org.apache.xpath.internal.axes.LocPathIterator;
3131
import com.sun.org.apache.xpath.internal.objects.XObject;
3232
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
33+
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
3334
import java.io.IOException;
35+
import javax.xml.XMLConstants;
3436
import javax.xml.namespace.QName;
3537
import javax.xml.parsers.DocumentBuilderFactory;
3638
import javax.xml.parsers.ParserConfigurationException;
@@ -54,7 +56,7 @@
5456
* This class contains several utility methods used by XPathImpl and
5557
* XPathExpressionImpl
5658
*
57-
* @LastModified: Jan 2022
59+
* @LastModified: June 2025
5860
*/
5961
class XPathImplUtil {
6062
XPathFunctionResolver functionResolver;
@@ -67,6 +69,7 @@ class XPathImplUtil {
6769
boolean featureSecureProcessing = false;
6870
JdkXmlFeatures featureManager;
6971
XMLSecurityManager xmlSecMgr;
72+
XMLSecurityPropertyManager xmlSecPropMgr;
7073

7174
/**
7275
* Evaluate an XPath context using the internal XPath engine
@@ -129,7 +132,12 @@ Document getDocument(InputSource source)
129132
//
130133
// so we really have to create a fresh DocumentBuilder every time we need one
131134
// - KK
132-
DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
135+
DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(
136+
overrideDefaultParser, xmlSecMgr, xmlSecPropMgr);
137+
if (xmlSecMgr != null && xmlSecMgr.isSecureProcessingSet()) {
138+
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,
139+
xmlSecMgr.isSecureProcessing());
140+
}
133141
return dbf.newDocumentBuilder().parse(source);
134142
} catch (ParserConfigurationException | SAXException | IOException e) {
135143
throw new XPathExpressionException (e);

0 commit comments

Comments
 (0)