summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGoetz Lindenmaier <goetz@openjdk.org>2026-11-18 15:59:08 +0000
committerGoetz Lindenmaier <goetz@openjdk.org>2026-11-18 15:59:08 +0000
commit8cdd95ea41ee695463e28c3798b83151c8bdfa4f (patch)
treed67483b924baee916e7c67e6c5b84f92447704f1
parente047bc2ed6c2256fd72824d2b83b0eaab94f3029 (diff)
parent10ebaa9a96d18973cfd08ec6828965886945f14f (diff)
downloadopenjdk-master.tar.gz
openjdk-master.zip
-rw-r--r--src/hotspot/cpu/x86/stubGenerator_x86_64.cpp4
-rw-r--r--src/hotspot/share/opto/loopnode.cpp10
-rw-r--r--src/java.base/share/classes/java/lang/AbstractStringBuilder.java24
-rw-r--r--src/java.base/share/classes/sun/security/ssl/DHServerKeyExchange.java11
-rw-r--r--src/java.base/share/classes/sun/security/ssl/ECDHServerKeyExchange.java11
-rw-r--r--src/java.base/share/classes/sun/security/ssl/ServerHelloDone.java11
-rw-r--r--src/java.base/share/classes/sun/security/ssl/ServerKeyExchange.java12
-rw-r--r--src/java.base/share/conf/security/java.security33
-rw-r--r--src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java83
-rw-r--r--src/java.security.jgss/share/classes/sun/security/krb5/KrbApReq.java81
-rw-r--r--src/java.security.jgss/share/classes/sun/security/krb5/internal/CredentialsUtil.java3
-rw-r--r--src/java.security.jgss/share/classes/sun/security/krb5/internal/Krb5.java20
-rw-r--r--src/java.security.jgss/share/classes/sun/security/krb5/internal/TicketFlags.java11
-rw-r--r--src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractMask.java127
-rw-r--r--src/jdk.jfr/share/classes/jdk/jfr/internal/EventWriter.java9
-rw-r--r--test/hotspot/jtreg/compiler/loopopts/TestTruncationWrapPhiTypeUnion.java221
-rw-r--r--test/jdk/sun/security/krb5/ErrorMessages.java63
-rw-r--r--test/jdk/sun/security/krb5/auto/KDC.java14
18 files changed, 664 insertions, 84 deletions
diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp
index fc454faeeba..62ea92b3056 100644
--- a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp
+++ b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp
@@ -6177,6 +6177,10 @@ address generate_avx_ghash_processBlocks() {
__ BIND(L_finalBit);
// Now have 1 to 63 bytes left to decode
+ // A padded Base64 tail shorter than one complete block is handled by Java.
+ __ cmpl(length, 4);
+ __ jcc(Assembler::less, L_bruteForce);
+
// I was going to let Java take care of the final fragment
// however it will repeatedly call this routine for every 4 bytes
// of input data, so handle the rest here.
diff --git a/src/hotspot/share/opto/loopnode.cpp b/src/hotspot/share/opto/loopnode.cpp
index 083179d491f..dc7b7c37bee 100644
--- a/src/hotspot/share/opto/loopnode.cpp
+++ b/src/hotspot/share/opto/loopnode.cpp
@@ -2749,6 +2749,7 @@ const TypeInt* PhaseIdealLoop::filtered_type( Node *n, Node* n_ctrl) {
Node* region = phi->in(0);
assert(n_ctrl == nullptr || n_ctrl == region, "ctrl parameter must be region");
if (region && region != C->top()) {
+ // Compute the union over the types of the paths/inputs.
for (uint i = 1; i < phi->req(); i++) {
Node* val = phi->in(i);
Node* use_c = region->in(i);
@@ -2759,10 +2760,17 @@ const TypeInt* PhaseIdealLoop::filtered_type( Node *n, Node* n_ctrl) {
} else {
filtered_t = filtered_t->meet(val_t)->is_int();
}
+ } else {
+ // We found no constriant, so we have to assume that this path
+ // is unconstrained, i.e. it could have the whole int range.
+ filtered_t = TypeInt::INT;
}
}
}
}
+
+ // The filtered type may be worse than what we already know
+ // about n, so take the intersection.
const TypeInt* n_t = _igvn.type(n)->is_int();
if (filtered_t != nullptr) {
n_t = n_t->join(filtered_t)->is_int();
@@ -2773,6 +2781,8 @@ const TypeInt* PhaseIdealLoop::filtered_type( Node *n, Node* n_ctrl) {
//------------------------------filtered_type_from_dominators--------------------------------
// Return a possibly more restrictive type for val based on condition control flow of dominators
+// Note: we can also return "nullptr", which means "no constraint", and should be interpreted
+// as if we returned TypeInt::INT.
const TypeInt* PhaseIdealLoop::filtered_type_from_dominators( Node* val, Node *use_ctrl) {
if (val->is_Con()) {
return val->bottom_type()->is_int();
diff --git a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java
index dc1afeaa10a..42b01227b20 100644
--- a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java
+++ b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2026, 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
@@ -222,6 +222,9 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
* overflow, this method throws {@code OutOfMemoryError}.
*/
private void ensureCapacityInternal(int minimumCapacity) {
+ if (minimumCapacity < 0) {
+ throwExcessiveLengthError();
+ }
// overflow-conscious code
int oldCapacity = value.length >> coder;
if (minimumCapacity - oldCapacity > 0) {
@@ -247,17 +250,17 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
* is greater than that.
*
* @param minCapacity the desired minimum capacity
- * @throws OutOfMemoryError if minCapacity is less than zero or
- * greater than (Integer.MAX_VALUE >> coder)
+ * @throws OutOfMemoryError if {@code minCapacity} is out of bounds
*/
private int newCapacity(int minCapacity) {
+ assert minCapacity >= 0 : "Invalid minimum capacity: " + minCapacity;
int oldLength = value.length;
- int newLength = minCapacity << coder;
- int growth = newLength - oldLength;
- int length = ArraysSupport.newLength(oldLength, growth, oldLength + (2 << coder));
- if (length == Integer.MAX_VALUE) {
- throw new OutOfMemoryError("Required length exceeds implementation limit");
+ long newLength = (long) minCapacity << coder;
+ if (newLength < 0 || newLength >= Integer.MAX_VALUE) {
+ throwExcessiveLengthError();
}
+ int growth = (int) newLength - oldLength;
+ int length = ArraysSupport.newLength(oldLength, growth, oldLength + (2 << coder));
return length >> coder;
}
@@ -1811,4 +1814,9 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
"start " + start + ", end " + end + ", length " + len);
}
}
+
+ private static void throwExcessiveLengthError() {
+ throw new OutOfMemoryError("Required length exceeds implementation limit");
+ }
+
}
diff --git a/src/java.base/share/classes/sun/security/ssl/DHServerKeyExchange.java b/src/java.base/share/classes/sun/security/ssl/DHServerKeyExchange.java
index af64383457a..d5d6a49b050 100644
--- a/src/java.base/share/classes/sun/security/ssl/DHServerKeyExchange.java
+++ b/src/java.base/share/classes/sun/security/ssl/DHServerKeyExchange.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2026, 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
@@ -200,6 +200,15 @@ final class DHServerKeyExchange {
}
if (x509Credentials == null) {
+ // Only anonymous key exchange is unsigned. For any other
+ // cipher suite the server Certificate message must have been
+ // received before the ServerKeyExchange message.
+ if (!chc.negotiatedCipherSuite.isAnonymous()) {
+ throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,
+ "No X.509 credentials negotiated for " +
+ "DH ServerKeyExchange: missing Certificate");
+ }
+
// anonymous, no authentication, no signature
if (m.hasRemaining()) {
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
diff --git a/src/java.base/share/classes/sun/security/ssl/ECDHServerKeyExchange.java b/src/java.base/share/classes/sun/security/ssl/ECDHServerKeyExchange.java
index 09b7a6bdca2..a288c6b68aa 100644
--- a/src/java.base/share/classes/sun/security/ssl/ECDHServerKeyExchange.java
+++ b/src/java.base/share/classes/sun/security/ssl/ECDHServerKeyExchange.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2026, 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
@@ -244,6 +244,15 @@ final class ECDHServerKeyExchange {
}
if (x509Credentials == null) {
+ // Only anonymous key exchange is unsigned. For any other
+ // cipher suite the server Certificate message must have been
+ // received before the ServerKeyExchange message.
+ if (!chc.negotiatedCipherSuite.isAnonymous()) {
+ throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,
+ "No X.509 credentials negotiated for " +
+ "ECDH ServerKeyExchange: missing Certificate");
+ }
+
// anonymous, no authentication, no signature
if (m.hasRemaining()) {
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
diff --git a/src/java.base/share/classes/sun/security/ssl/ServerHelloDone.java b/src/java.base/share/classes/sun/security/ssl/ServerHelloDone.java
index 7136b36ffc2..5ae1981a5e7 100644
--- a/src/java.base/share/classes/sun/security/ssl/ServerHelloDone.java
+++ b/src/java.base/share/classes/sun/security/ssl/ServerHelloDone.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2026, 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
@@ -133,6 +133,15 @@ final class ServerHelloDone {
// The consuming happens in client side only.
ClientHandshakeContext chc = (ClientHandshakeContext)context;
+ // Check for an unprocessed server Certificate message. If
+ // that handshake consumer is still present then that expected
+ // message was not sent.
+ if (chc.handshakeConsumers.containsKey(
+ SSLHandshake.CERTIFICATE.id)) {
+ throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,
+ "Unexpected ServerHelloDone handshake message.");
+ }
+
SSLConsumer certStatCons = chc.handshakeConsumers.remove(
SSLHandshake.CERTIFICATE_STATUS.id);
if (certStatCons != null) {
diff --git a/src/java.base/share/classes/sun/security/ssl/ServerKeyExchange.java b/src/java.base/share/classes/sun/security/ssl/ServerKeyExchange.java
index be5814acc50..19fa2584ad8 100644
--- a/src/java.base/share/classes/sun/security/ssl/ServerKeyExchange.java
+++ b/src/java.base/share/classes/sun/security/ssl/ServerKeyExchange.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2026, 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
@@ -92,6 +92,15 @@ final class ServerKeyExchange {
// clean up this consumer
chc.handshakeConsumers.remove(SSLHandshake.SERVER_KEY_EXCHANGE.id);
+ // If the Certificate consumer is still registered, the server
+ // omitted the required Certificate message before sending
+ // ServerKeyExchange.
+ if (chc.handshakeConsumers.containsKey(
+ SSLHandshake.CERTIFICATE.id)) {
+ throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE,
+ "Unexpected ServerKeyExchange handshake message.");
+ }
+
// Any receipt/consumption of the CertificateRequest before
// ServerKeyExchange is a state machine violation. We may not
// know for sure if an early CR message is a violation though until
@@ -131,4 +140,3 @@ final class ServerKeyExchange {
}
}
}
-
diff --git a/src/java.base/share/conf/security/java.security b/src/java.base/share/conf/security/java.security
index 81d36db0e00..bbdb90c03c9 100644
--- a/src/java.base/share/conf/security/java.security
+++ b/src/java.base/share/conf/security/java.security
@@ -495,6 +495,39 @@ sun.security.krb5.disableReferrals=false
sun.security.krb5.maxReferrals=5
#
+# Policy for Kerberos service transited field checking:
+#
+# In cross-realm authentication, if the service ticket includes a non-empty
+# transited field but the ticket flags do not have TRANSIT-POLICY-CHECKED set,
+# the application server should perform the transited-realm checks itself.
+# This is required in Section 2.7 of RFC 4120.
+#
+# This property determines whether the server performs the transited-realm
+# check when the service ticket does not have the TRANSIT-POLICY-CHECKED flag
+# set. If the value is set to "true", the JDK performs the check when
+# GSSContext.acceptSecContext is called to process the incoming context-
+# establishment token, which contains the service ticket.
+#
+# The check uses the explicit paths configured in the [capaths] section of
+# krb5.conf, or if that is not configured, uses an implicit hierarchical
+# relationship between realm names. If any of the realms encoded in the
+# transited field are not allowed, the context establishment will fail.
+# If the value is set to "false", no check is performed. The default value
+# of this property is "true".
+#
+# This property should be used at your own risk.
+#
+# If a system property of the same name is also specified, it supersedes the
+# security property value defined here.
+#
+# Note: This property is currently used by the Java Kerberos GSS-API mechanism
+# of the JDK Reference implementation. An application using native GSS-API
+# does not use this property; instead it follows the policy of the underlying
+# native GSS library. Support for this property is not guaranteed in other
+# Java SE implementations.
+sun.security.krb5.acceptor.checkTransitedPolicy = true
+
+#
# This property contains a list of disabled EC Named Curves that can be included
# in the jdk.[tls|certpath|jar].disabledAlgorithms properties. To include this
# list in any of the disabledAlgorithms properties, add the property name as
diff --git a/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java b/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java
index 7a903122ad7..2127ae5ad65 100644
--- a/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java
+++ b/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java
@@ -35,6 +35,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InvalidObjectException;
+import java.io.ObjectInputFilter;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.io.Serializable;
@@ -1847,6 +1848,79 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable
return (RMIServer) objref;
}
+ /**
+ * ObjectInputFilter implementation for JMXServiceURL.
+ * Optional filters may be set from the env and System Property.
+ * If not decisive, the default filter is checked.
+ */
+ private static final class JMXURLObjectInputFilter implements ObjectInputFilter {
+
+ // Default filter. Intentionally does NOT end in "!*", to leave some classes UNDECIDED.
+ private static final String DEFAULT_URL_FILTER_PATTERN =
+ // Permit proxy classes including older style jdk.proxy1.$Proxy0
+ "java.lang.reflect.Proxy;" +
+ "java.rmi.server.RemoteObjectInvocationHandler;" +
+ "jdk.proxy*;" +
+ "java.rmi.server.RemoteStub;" +
+ "java.rmi.server.RemoteObject;" +
+ "javax.management.remote.rmi.RMIServerImpl_Stub;";
+
+ private static final String URL_FILTER_OVERRIDE_PATTERN_NAME = "jmx.remote.rmi.connector.url.filter.pattern";
+
+ private final ObjectInputFilter envFilter;
+
+ private final ObjectInputFilter systemPropertyFilter;
+
+ private final ObjectInputFilter defaultFilter;
+
+ private static ObjectInputFilter filterFromPattern(String pattern) {
+ // createFilter returns null on empty pattern (pattern must not be null)
+ return ObjectInputFilter.Config.createFilter(pattern != null ? pattern : "");
+ }
+
+ @SuppressWarnings("removal")
+ public JMXURLObjectInputFilter(Map<String, ?> env) {
+ envFilter = filterFromPattern((String) env.get(URL_FILTER_OVERRIDE_PATTERN_NAME));
+ systemPropertyFilter = filterFromPattern(
+ AccessController.doPrivileged((PrivilegedAction<String>) () -> {
+ return System.getProperty(URL_FILTER_OVERRIDE_PATTERN_NAME);
+ }));
+ defaultFilter = ObjectInputFilter.Config.createFilter(DEFAULT_URL_FILTER_PATTERN);
+ }
+
+ @Override
+ public Status checkInput(FilterInfo info) {
+ Status status = Status.UNDECIDED;
+ // Check custom filters, if set. Try next filter if UNDECIDED.
+ if (envFilter != null) {
+ status = envFilter.checkInput(info);
+ if (status != Status.UNDECIDED) {
+ return status;
+ }
+ }
+ if (systemPropertyFilter != null) {
+ status = systemPropertyFilter.checkInput(info);
+ if (status != Status.UNDECIDED) {
+ return status;
+ }
+ }
+ status = defaultFilter.checkInput(info);
+ if (status != Status.UNDECIDED) {
+ return status;
+ }
+ // Finally, permit client socket factory or RMIServer, to avoid requiring an exhaustive filter.
+ // Otherwise, return REJECTED.
+ Class<?> c = info.serialClass();
+ if (RMIClientSocketFactory.class.isAssignableFrom(c)
+ || RMIServer.class.isAssignableFrom(c)) {
+ return Status.ALLOWED;
+ } else {
+ return Status.REJECTED;
+ }
+ }
+ }
+
+ @SuppressWarnings("removal")
private RMIServer findRMIServerJRMP(String base64, Map<String, ?> env)
throws IOException {
final byte[] serialized;
@@ -1863,13 +1937,20 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable
(loader == null) ?
new ObjectInputStream(bin) :
new ObjectInputStreamWithLoader(bin, loader);
+
+ final JMXURLObjectInputFilter filter = new JMXURLObjectInputFilter(env);
+ AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+ oin.setObjectInputFilter(filter);
+ return null;
+ });
+
final Object stub;
try {
stub = oin.readObject();
} catch (ClassNotFoundException e) {
throw new MalformedURLException("Class not found: " + e);
}
- return (RMIServer)stub;
+ return (RMIServer) stub;
}
private static final class ObjectInputStreamWithLoader
diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/KrbApReq.java b/src/java.security.jgss/share/classes/sun/security/krb5/KrbApReq.java
index c4f520fe812..8646bd00ed4 100644
--- a/src/java.security.jgss/share/classes/sun/security/krb5/KrbApReq.java
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/KrbApReq.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2026, 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
@@ -37,9 +37,15 @@ import sun.security.jgss.krb5.Krb5AcceptCredential;
import java.net.InetAddress;
import sun.security.util.*;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.Arrays;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
import sun.security.krb5.internal.rcache.AuthTimeWithHash;
/**
@@ -340,12 +346,52 @@ public class KrbApReq {
}
}
- // XXX check for repeated authenticator
- // if found
- // throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
- // else
- // save authenticator to check for later
+ if (DEBUG) {
+ System.out.println(">>> KrbApReq: Received ticket options " + enc_ticketPart.flags);
+ }
+ if (!enc_ticketPart.flags.get(Krb5.TKT_OPTS_TRANSIT_POLICY_CHECKED)
+ && enc_ticketPart.transited.contents.length != 0) {
+ // System property to control transited policy check:
+ //
+ // If true, compare transited field inside the service ticket to
+ // local settings, and fail with KRB_AP_PATH_NOT_ACCEPTED if there
+ // is no match. Otherwise, ignore the check.
+ //
+ // Default value is `true`. Set to `false` to revert to old behavior.
+ String propValue = SecurityProperties.privilegedGetOverridable(
+ "sun.security.krb5.acceptor.checkTransitedPolicy");
+ boolean checkTransitedPolicy = true; // default
+ if (propValue != null) {
+ propValue = propValue.toLowerCase(Locale.ROOT);
+ checkTransitedPolicy = switch (propValue) {
+ case "true" -> true;
+ case "false" -> false;
+ default -> throw new IllegalArgumentException(
+ "Invalid property value: " + propValue);
+ };
+ }
+ if (checkTransitedPolicy) {
+ if (enc_ticketPart.transited.trType == Krb5.DOMAIN_X500_COMPRESS) {
+ String transited = new String(
+ enc_ticketPart.transited.contents, StandardCharsets.UTF_8);
+ String cRealm = enc_ticketPart.cname.getRealmAsString();
+ String sRealm = apReqMessg.ticket.sname.getRealmAsString();
+ String[] allowed = Realm.getRealmsList(cRealm, sRealm);
+ if (DEBUG) {
+ System.out.println(">>> KrbApReq: transited realm is " + transited
+ + ", allowed is " + Arrays.toString(allowed)
+ + ". Checking from " + cRealm + " to " + sRealm);
+ }
+ List<String> inTicket = parseTransited(transited);
+ if (!Set.of(allowed).containsAll(inTicket)) {
+ throw new KrbApErrException(Krb5.KRB_AP_PATH_NOT_ACCEPTED);
+ }
+ } else {
+ throw new KrbApErrException(Krb5.KRB_AP_PATH_NOT_ACCEPTED);
+ }
+ }
+ }
KerberosTime now = KerberosTime.now();
if ((enc_ticketPart.starttime != null &&
@@ -379,6 +425,29 @@ public class KrbApReq {
}
}
+ // https://datatracker.ietf.org/doc/html/rfc4120#section-3.3.3.2
+ // Only support "," and "." as special characters.
+ private static List<String> parseTransited(String input)
+ throws KrbApErrException {
+ ArrayList<String> output = new ArrayList<>();
+ String last = null;
+ for (String s : input.split(",", -1)) {
+ if (s == null || s.isEmpty() || s.contains("/")
+ || s.contains("\\") || s.contains(" ")) {
+ throw new KrbApErrException(Krb5.KRB_AP_PATH_NOT_ACCEPTED);
+ }
+ if (s.endsWith(".")) {
+ if (last == null) {
+ throw new KrbApErrException(Krb5.KRB_AP_PATH_NOT_ACCEPTED);
+ }
+ s = s + last;
+ }
+ output.add(s);
+ last = s;
+ }
+ return output;
+ }
+
/**
* Returns the credentials that are contained in the ticket that
* is part of this AP-REQ.
diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/internal/CredentialsUtil.java b/src/java.security.jgss/share/classes/sun/security/krb5/internal/CredentialsUtil.java
index 1f5f033c58b..2953a0f5782 100644
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/CredentialsUtil.java
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/CredentialsUtil.java
@@ -455,8 +455,7 @@ public class CredentialsUtil {
Credentials newTgt = getTGTforRealm(tgtRealm, serviceRealm,
asCreds, okAsDelegate);
if (newTgt == null) {
- throw new KrbApErrException(Krb5.KRB_AP_ERR_GEN_CRED,
- "No service creds");
+ throw new KrbException("No service creds");
}
if (DEBUG) {
System.out.println(">>> Cross-realm TGT Credentials" +
diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/internal/Krb5.java b/src/java.security.jgss/share/classes/sun/security/krb5/internal/Krb5.java
index 93831f5a3e6..e2da0a3b1cd 100644
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/Krb5.java
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/Krb5.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2026, 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
@@ -71,6 +71,7 @@ public class Krb5 {
public static final int TKT_OPTS_INITIAL = 9;
public static final int TKT_OPTS_PRE_AUTHENT = 10;
public static final int TKT_OPTS_HW_AUTHENT = 11;
+ public static final int TKT_OPTS_TRANSIT_POLICY_CHECKED = 12;
public static final int TKT_OPTS_DELEGATE = 13;
public static final int TKT_OPTS_ENC_PA_REP = 15;
public static final int TKT_OPTS_MAX = 31;
@@ -250,6 +251,9 @@ public class Krb5 {
public static final int KDC_ERR_KEY_EXPIRED = 23; //Password has expired - change password to reset
public static final int KDC_ERR_PREAUTH_FAILED = 24; //Pre-authentication information was invalid
public static final int KDC_ERR_PREAUTH_REQUIRED = 25; //Additional pre-authentication required
+ public static final int KDC_ERR_SERVER_NOMATCH = 26; //Requested server and ticket don't match
+ public static final int KDC_ERR_MUST_USE_USER2USER = 27; //Server principal valid for user2user only
+ public static final int KDC_ERR_PATH_NOT_ACCEPTED = 28; //KDC Policy rejects transited path
public static final int KDC_ERR_SVC_UNAVAILABLE = 29; //A service is not available
public static final int KRB_AP_ERR_BAD_INTEGRITY = 31; //Integrity check on decrypted field failed
public static final int KRB_AP_ERR_TKT_EXPIRED = 32; //Ticket expired
@@ -270,13 +274,13 @@ public class Krb5 {
public static final int KRB_AP_ERR_METHOD = 48; //Alternative authentication method required
public static final int KRB_AP_ERR_BADSEQ = 49; //Incorrect sequence number in message
public static final int KRB_AP_ERR_INAPP_CKSUM = 50; //Inappropriate type of checksum in message
+ public static final int KRB_AP_PATH_NOT_ACCEPTED = 51; //Policy rejects transited path
public static final int KRB_ERR_RESPONSE_TOO_BIG = 52; //Response too big for UDP, retry with TCP
public static final int KRB_ERR_GENERIC = 60; //Generic error (description in e-text)
public static final int KRB_ERR_FIELD_TOOLONG = 61; //Field is too long for this implementation
public static final int KRB_ERR_WRONG_REALM = 68; //Wrong realm
- public static final int KRB_CRYPTO_NOT_SUPPORT = 100; //Client does not support this crypto type
- public static final int KRB_AP_ERR_NOREALM = 62;
- public static final int KRB_AP_ERR_GEN_CRED = 63;
+
+ public static final int KRB_CRYPTO_NOT_SUPPORT = 100; //Client does not support this crypto type
// public static final int KRB_AP_ERR_CKSUM_NOKEY =101; //Lack of the key to generate the checksum
// error codes specific to this implementation
public static final int KRB_AP_ERR_REQ_OPTIONS = 101; //Invalid TGS_REQ
@@ -343,6 +347,10 @@ public class Krb5 {
errMsgList.put(KDC_ERR_KEY_EXPIRED, "Password has expired - change password to reset");
errMsgList.put(KDC_ERR_PREAUTH_FAILED, "Pre-authentication information was invalid");
errMsgList.put(KDC_ERR_PREAUTH_REQUIRED, "Additional pre-authentication required");
+ errMsgList.put(KDC_ERR_SERVER_NOMATCH, "Requested server and ticket don't match");
+ errMsgList.put(KDC_ERR_MUST_USE_USER2USER, "Server principal valid for user2user only");
+ errMsgList.put(KDC_ERR_PATH_NOT_ACCEPTED, "KDC Policy rejects transited path");
+ errMsgList.put(KDC_ERR_SVC_UNAVAILABLE, "A service is not available");
errMsgList.put(KRB_AP_ERR_BAD_INTEGRITY, "Integrity check on decrypted field failed");
errMsgList.put(KRB_AP_ERR_TKT_EXPIRED, "Ticket expired");
errMsgList.put(KRB_AP_ERR_TKT_NYV, "Ticket not yet valid");
@@ -362,10 +370,11 @@ public class Krb5 {
errMsgList.put(KRB_AP_ERR_METHOD, "Alternative authentication method required");
errMsgList.put(KRB_AP_ERR_BADSEQ, "Incorrect sequence number in message");
errMsgList.put(KRB_AP_ERR_INAPP_CKSUM, "Inappropriate type of checksum in message");
+ errMsgList.put(KRB_AP_PATH_NOT_ACCEPTED, "Policy rejects transited path");
errMsgList.put(KRB_ERR_RESPONSE_TOO_BIG, "Response too big for UDP, retry with TCP");
errMsgList.put(KRB_ERR_GENERIC, "Generic error (description in e-text)");
errMsgList.put(KRB_ERR_FIELD_TOOLONG, "Field is too long for this implementation");
- errMsgList.put(KRB_AP_ERR_NOREALM, "Realm name not available"); //used in setDefaultCreds() in sun.security.krb5.Credentials
+ errMsgList.put(KRB_ERR_WRONG_REALM, "Wrong realm");
// error messages specific to this implementation
@@ -395,7 +404,6 @@ public class Krb5 {
errMsgList.put(ASN1_CANNOT_ENCODE, "Encoding failed due to invalid parameter(s)");
errMsgList.put(KRB_CRYPTO_NOT_SUPPORT, "Client has no support for crypto type");
errMsgList.put(KRB_AP_ERR_REQ_OPTIONS, "Invalid option setting in ticket request.");
- errMsgList.put(KRB_AP_ERR_GEN_CRED, "Fail to create credential.");
}
}
diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/internal/TicketFlags.java b/src/java.security.jgss/share/classes/sun/security/krb5/internal/TicketFlags.java
index cc1951f370c..294a4e69c9d 100644
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/TicketFlags.java
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/TicketFlags.java
@@ -52,6 +52,8 @@ import java.io.IOException;
* initial(9),
* pre-authent(10),
* hw-authent(11),
+ * transited-policy-checked(12),
+ * ok-as-delegate(13)
* enc-pa-rep(15)
* }
*/
@@ -180,9 +182,18 @@ public class TicketFlags extends KerberosFlags {
case 11:
sb.append("HW-AUTHENT;");
break;
+ case 12:
+ sb.append("TRANSIT-POLICY-CHECKED;");
+ break;
+ case 13:
+ sb.append("OK-AS-DELEGATE;");
+ break;
case 15:
sb.append("ENC-PA-REP;");
break;
+ default:
+ sb.append(i).append(";");
+ break;
}
}
}
diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractMask.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractMask.java
index 81855a4af7d..ac55c58996c 100644
--- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractMask.java
+++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractMask.java
@@ -194,83 +194,104 @@ abstract class AbstractMask<E> extends VectorMask<E> {
*/
/*package-private*/
@ForceInline
- void checkIndexByLane(int offset, int alength,
+ void checkIndexByLane(long offset, long length,
Vector<E> iota,
int esize) {
if (VectorIntrinsics.VECTOR_ACCESS_OOB_CHECK == 0) {
return;
}
- // Although the specification is simple, the implementation is
- // tricky, because the value iota*esize might possibly
- // overflow. So we calculate our test values as scalars,
- // clipping to the range [-1..VLENGTH], and test them against
- // the unscaled iota vector, whose values are in [0..VLENGTH-1].
+ assert length >= 0;
int vlength = length();
- VectorMask<E> badMask;
- if (esize == 1) {
- badMask = checkIndex0(offset, alength, iota, vlength);
- } else if (offset >= 0) {
- // Masked access to multi-byte lanes in byte array.
- // It could be aligned anywhere.
- int elemCount = Math.min(vlength, (alength - offset) / esize);
- badMask = checkIndex0(0, elemCount, iota, vlength);
- } else {
- // This requires a split test.
- int clipOffset = Math.max(offset, -(vlength * esize));
- int elemCount = Math.min(vlength, (alength - clipOffset) / esize);
- badMask = checkIndex0(0, elemCount, iota, vlength);
- clipOffset &= (esize - 1); // power of two, so OK
- VectorMask<E> badMask2 = checkIndex0(clipOffset / esize, vlength,
- iota, vlength);
- badMask = badMask.or(badMask2);
- }
+ // badMask marks lanes that are not valid, i.e. fall outside
+ // the segment.
+
+ // The implementation assumes that iota*esize will not overflow.
+ VectorMask<E> badMask = checkIndex0(offset, length - esize + 1,
+ iota.lanewise(VectorOperators.MUL, esize),
+ vlength * esize);
badMask = badMask.and(this);
+ // if any active lanes fall outside, throw.
if (badMask.anyTrue()) {
int badLane = badMask.firstTrue();
throw ((AbstractMask<E>)badMask)
- .checkIndexFailed(offset, badLane, alength, esize);
+ .checkIndexFailed(offset, badLane, length, esize);
}
}
private
@ForceInline
- VectorMask<E> checkIndex0(int offset, int alength,
- Vector<E> iota, int vlength) {
- // An active lane is bad if its number is greater than
- // alength-offset, since when added to offset it will step off
- // of the end of the array. To avoid overflow when
- // converting, clip the comparison value to [0..vlength]
- // inclusive.
- int indexLimit = Math.max(0, Math.min(alength - offset, vlength));
- VectorMask<E> badMask =
- iota.compare(GE, iota.broadcast(indexLimit));
+ VectorMask<E> checkIndex0(long offset, long length,
+ Vector<E> iotaScaled, int vlengthScaled) {
+ // This method takes:
+ // - vector length scaled by esize (vlengthScaled)
+ // - vector of lane offsets for the given vector type
+ // with values (0, esize, 2 * esize, ..., vlengthScaled - esize) (iotaScaled)
+ // - an offset into the segment at which the access
+ // will take place (offset)
+ // - the length of the segment, reduced by esize - 1 (length)
+ // Returns a mask where bad lanes are set to true
+ // and good lanes are set to false.
+ // Bad lanes are defined as lanes whose offset falls below 0
+ // or above length.
+ // Technically, the algorithm is equivalent to:
+ // offsets = iotaScaled + offset
+ // mask = !(0 <= offsets < length)
+ // except it's trying hard to avoid overflows.
+
+ // iotaScaled is scaled by esize, it is the caller's responsibility
+ // to adjust the length down by esize - 1 to ensure that the lanes
+ // completely fit in bounds. If esize = 1 no adjustment is required.
+
+ // The algorithm assumes that:
+ // - values in iotaScaled are between [0, vlengthScaled)
+ // - vector type can represent values in [0, vlengthScaled) range with full precision
+ // (this will not work for float8)
+ assert vlengthScaled > 0;
+ if (length < offset || length < 0 || offset <= -vlengthScaled) {
+ return vectorSpecies().maskAll(true);
+ }
+
+ // For each index i, the access at i is in-bounds if and only if
+ // 0 <= offset + i < length
if (offset < 0) {
- // An active lane is bad if its number is less than
- // -offset, because when added to offset it will then
- // address an array element at a negative index. To avoid
- // overflow when converting, clip the comparison value at
- // vlength. This specific expression works correctly even
- // when offset is Integer.MIN_VALUE.
- int firstGoodIndex = -Math.max(offset, -vlength);
- VectorMask<E> badMask2 =
- iota.compare(LT, iota.broadcast(firstGoodIndex));
- if (indexLimit >= vlength) {
- badMask = badMask2; // 1st badMask is all true
+ // 0 <= offset + i is equivalent to E(-offset) < i;
+ // E(-offset) will be precise because -vlengthScaled < offset < 0
+ VectorMask<E> lowMask =
+ iotaScaled.compare(LT, iotaScaled.broadcast(-offset));
+ // check if we need to mask lanes above length.
+ // offset < 0 and vlengthScaled > 0, so offset + vlengthScaled will not overflow
+ if (offset + vlengthScaled > length) {
+ // offset + i < length is equivalent to i < E(length - offset)
+ // E(length - offset) will be precise because 0 <= length - offset < vlengthScaled
+ VectorMask<E> highMask =
+ iotaScaled.compare(GE, iotaScaled.broadcast(length - offset));
+ return highMask.or(lowMask);
+
} else {
- badMask = badMask.or(badMask2);
+ return lowMask;
}
+ } else {
+ // 0 <= offset + i is guaranteed here because offset >= 0 and i >= 0
+ // offset + i < length is equivalent to i < E(min(vlengthScaled, length - offset))
+ // length - offset will not underflow because 0 <= offset <= length,
+ // length - offset can be clamped to vlengthScaled because i < vlengthScaled.
+
+ // Alternatively, we could directly return an all-false mask if length - offset >= vlengthScaled.
+ int indexLimit = (int) Math.min(Math.max(length - offset, 0), vlengthScaled);
+ VectorMask<E> highMask =
+ iotaScaled.compare(GE, iotaScaled.broadcast(indexLimit));
+ return highMask;
}
- return badMask;
}
- private IndexOutOfBoundsException checkIndexFailed(int offset, int lane,
- int alength, int esize) {
+ private IndexOutOfBoundsException checkIndexFailed(long offset, int lane,
+ long length, int esize) {
String msg = String.format("Masked range check failed: "+
"vector mask %s out of bounds at "+
- "index %d+%d in array of length %d",
- this, offset, lane * esize, alength);
+ "index %d+%d for length %d",
+ this, offset, lane * esize, length);
if (esize != 1) {
- msg += String.format(" (each lane spans %d array elements)", esize);
+ msg += String.format(" (each lane spans %d elements)", esize);
}
throw new IndexOutOfBoundsException(msg);
}
diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventWriter.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventWriter.java
index c61933302f5..e52abe86898 100644
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventWriter.java
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2026, 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
@@ -141,7 +141,12 @@ public final class EventWriter {
private void putStringValue(String s) {
int length = s.length();
- if (isValidForSize(1 + 5 + 3 * length)) {
+ long size = 1L + 5L + 3L * length;
+ if (size > Integer.MAX_VALUE) {
+ valid = false;
+ return;
+ }
+ if (isValidForSize((int)size)) {
putUncheckedByte(StringParser.Encoding.CHAR_ARRAY.byteValue()); // 1 byte
putUncheckedInt(length); // max 5 bytes
for (int i = 0; i < length; i++) {
diff --git a/test/hotspot/jtreg/compiler/loopopts/TestTruncationWrapPhiTypeUnion.java b/test/hotspot/jtreg/compiler/loopopts/TestTruncationWrapPhiTypeUnion.java
new file mode 100644
index 00000000000..a7873359b45
--- /dev/null
+++ b/test/hotspot/jtreg/compiler/loopopts/TestTruncationWrapPhiTypeUnion.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2026, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package compiler.loopopts;
+
+/*
+ * @test
+ * @bug 8386830
+ * @summary Test for CountedLoopConverter::filtered_type, where we wrongly
+ * ignored a nullptr type, and returned a type that was too narrow,
+ * which led us to wrongly ignore wrapping in
+ * CountedLoopConverter::has_truncation_wrap
+ * @library /test/lib /
+ * @run main/othervm -Xbatch
+ * -XX:CompileCommand=compileonly,${test.main.class}::test*
+ * ${test.main.class}
+ * @run main ${test.main.class}
+ */
+public class TestTruncationWrapPhiTypeUnion {
+
+ interface TestMethod {
+ int call();
+ }
+
+ public static void main(String[] args) {
+ int failures = 0;
+
+ failures += run("test1", () -> test1(-1), 11111);
+ failures += run("test2", () -> test2(-1), 11111);
+ failures += run("test3", () -> test3(-100_000), -87065049);
+ failures += run("test4", () -> test4(32770), 10330);
+ failures += run("test5", () -> test5(-63), 10340);
+
+ if (failures > 0) {
+ throw new RuntimeException("failures: " + failures);
+ }
+ }
+
+ static int run(String name, TestMethod t, int expected) {
+ for (int i = 0; i < 20; i++) {
+ int result = t.call();
+ if (result != expected) {
+ System.out.println(name + " wrong result: " + result + " vs " + expected);
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+ static int test1(int limit) {
+ int x = 0;
+ int sum = 0;
+
+ limit = (byte) limit; // type BYTE = [-128..127], at runtime: -1
+
+ int i = 510;
+ while (limit < i) {
+ // Exit check checks for positive values, but with
+ // entry 510 and unsigned truncation, that can never fail.
+
+ sum++;
+
+ // Secondary exit check, to make sure we exit eventually.
+ if (++x >= 11111) {
+ break;
+ }
+
+ // Unsigned 15-bit truncation.
+ // We check for wrap/truncation/underflow:
+ //
+ // } else if (stride_con < 0) {
+ // if (truncation.trunc_type()->lo_as_long() - phi_ft->lo_as_long() > stride_con ||
+ // truncation.trunc_type()->hi_as_long() < phi_ft->hi_as_long()) {
+ // return true; // truncation may occur
+ // }
+ // }
+ //
+ // The lo of truncation is 0, and also the phi type should have a lo of 0,
+ // but it was wrongly determined to be 510.
+ // So, whereas "0 - 0 > -10" would have given us the required "true",
+ // we now checked "0 - 510 > -10", which was wrongly "false".
+ //
+ // The reason is that the phi_ft has been wrongly determined to be 510,
+ // so only considering the entry value. This is determined inside filtered_type:
+ // - entry: filtered_type_from_dominators discovers entry value 510.
+ // - backedge: filtered_type_from_dominators discovers no dominating-if, returns nullptr.
+ // But filtered_type skips nullptr results, as in "no extra filter". But
+ // we should be accumulating the entry and backedge type here!
+ //
+ // The only if on the backedge-path would have been the exit
+ // check: limit < i. But filtered_int_type finds nothing, returns nullptr.
+ i = (i - 10) & 0x7fff;
+ }
+
+ return sum;
+ }
+
+ // Note: this case was first discovered during JDK-8386591, which enabled 0xffff masking.
+ // Without allowing 0xffff masking, this did not fail. But it was the way I
+ // first discovered the bug, and so I wanted to add this as a test anyway.
+ static int test2(int limit) {
+ int x = 0;
+ int sum = 0;
+
+ limit = (short) limit; // type SHORT = [-32768..32767], at runtime: -1
+
+ int i = 510;
+ while (limit < i) {
+ // Exit check checks for positive values, but with
+ // entry 510 and unsigned truncation, that can never fial.
+
+ sum++;
+
+ // Secondary exit check, to make sure we exit eventually.
+ if (++x >= 11111) {
+ break;
+ }
+
+ // CHAR truncation: 0..0xffff = 0..65535
+ //
+ // i iterates: 510, 500, ... 10, 0
+ // And then, it shshould ould underflows: (0 - 10) & 0xffff = 65526
+ //
+ // But in CountedLoopConverter::has_truncation_wrap, we wrongly
+ // decide there cannot be overflow.
+ // truncation: [0..65535]
+ // stride_con: -10
+ //
+ // Accordingly, phi_ft should be in [0..65535], and so when we check
+ // for underflow, we check:
+ //
+ // } else if (stride_con < 0) {
+ // if (truncation.trunc_type()->lo_as_long() - phi_ft->lo_as_long() > stride_con ||
+ // truncation.trunc_type()->hi_as_long() < phi_ft->hi_as_long()) {
+ // return true; // truncation may occur
+ // }
+ // }
+ //
+ // So we should check: 0 - 0 > -10, and we would see that truncation could occur.
+ // But instead, we checked 0 - 510 > -10, which wronly lead to "no truncation".
+ //
+ // The reason is that the phi_ft has been wrongly determined to be 510,
+ // so only considering the entry value. This is determined inside filtered_type:
+ // - entry: filtered_type_from_dominators discovers entry value 510.
+ // - backedge: filtered_type_from_dominators discovers no dominating-if, returns nullptr.
+ // But filtered_type skips nullptr results, as in "no extra filter". But
+ // we should be accumulating the entry and backedge type here!
+ //
+ // The only if on the backedge-path would have been the exit
+ // check: limit < i. But filtered_int_type finds nothing, returns nullptr.
+ i = (i - 10) & 0xffff;
+ }
+
+ return sum;
+ }
+
+ // Another fuzzer find, this one with short truncation.
+ static int test3(int limit) {
+ int x = 0;
+ int sum = 0;
+
+ // Range: [min_int..8192], at runtime: -100_000
+ limit = Math.min(limit, 8192);
+ int i;
+ for (i = 128; limit <= i; i = (short)(i - 16384)) {
+ sum = sum + i + 1;
+ if (x++ > 10789) {
+ break;
+ }
+ }
+ return sum + i;
+ }
+
+ // Another fuzzer find, this one with short truncation.
+ static int test4(int limit) {
+ int sum = 0;
+ int x = 0;
+ limit = (short) limit;
+ for (int i = -1025; limit <= i; i = (short) (i + -7)) {
+ sum = sum + 1;
+ if (x++ > 10328) {
+ break;
+ }
+ }
+ return sum;
+ }
+
+ // Another fuzzer find, again with 0x7fff mask.
+ static int test5(int limit) {
+ int x = 0;
+ int sum = 0;
+ limit = (byte)limit;
+ for (int i = 8192; limit < i; i = ((i + -8) & 0x7fff)) {
+ sum++;
+ if (x++ > 10338) {
+ break;
+ }
+ }
+ return sum;
+ }
+}
diff --git a/test/jdk/sun/security/krb5/ErrorMessages.java b/test/jdk/sun/security/krb5/ErrorMessages.java
new file mode 100644
index 00000000000..b233e3d290e
--- /dev/null
+++ b/test/jdk/sun/security/krb5/ErrorMessages.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2023, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+/*
+ * @test
+ * @bug 8316771
+ * @library /test/lib
+ * @modules java.security.jgss/sun.security.krb5.internal:+open
+ * @summary make sure each error code has a message
+ */
+
+import jdk.test.lib.Asserts;
+import sun.security.krb5.internal.Krb5;
+
+import java.lang.reflect.Field;
+import java.util.Hashtable;
+
+public class ErrorMessages {
+ public static void main(String[] args) throws Exception {
+ boolean isError = false;
+ int count = 0;
+ int size = -1;
+ for (Field v : Krb5.class.getDeclaredFields()) {
+ // The spec of the Class::getDeclaredFields method claims
+ // "The elements in the returned array are not sorted and
+ // are not in any particular order". However, the current
+ // implementation seems to be listing them in the order
+ // they appear in the code.
+ if (v.getName().equals("errMsgList")) {
+ v.setAccessible(true);
+ size = ((Hashtable)v.get(null)).size();
+ break;
+ }
+ if (v.getName().equals("KDC_ERR_NONE")) {
+ isError = true;
+ }
+ if (!isError) continue;
+ Asserts.assertNotEquals(Krb5.getErrorMessage((int)v.get(null)),
+ null, "No msg for " + v);
+ count++;
+ }
+ Asserts.assertEQ(count, size, "Different size");
+ }
+}
diff --git a/test/jdk/sun/security/krb5/auto/KDC.java b/test/jdk/sun/security/krb5/auto/KDC.java
index c4fce1c06e6..df09fab3853 100644
--- a/test/jdk/sun/security/krb5/auto/KDC.java
+++ b/test/jdk/sun/security/krb5/auto/KDC.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2026, 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
@@ -996,6 +996,9 @@ public class KDC {
body.addresses != null ? body.addresses
: etp.caddr,
null);
+
+ enc = modifyEncTicketPart(1, enc);
+
EncryptionKey skey = keyForUser(service, e3, true);
if (skey == null) {
throw new KrbException(Krb5.KDC_ERR_SUMTYPE_NOSUPP); // TODO
@@ -1056,6 +1059,12 @@ public class KDC {
}
}
+ // Overridable by subclass to modify a ticket before encryption.
+ // type is 0 for AS-REQ and 1 for TGS-REQ.
+ protected EncTicketPart modifyEncTicketPart(int type, EncTicketPart enc) {
+ return enc;
+ }
+
/**
* Processes a AS_REQ and generates a AS_REP (or KRB_ERROR)
* @param in the request
@@ -1341,6 +1350,9 @@ public class KDC {
till, rtime,
body.addresses,
null);
+
+ enc = modifyEncTicketPart(0, enc);
+
Ticket t = new Ticket(
service,
new EncryptedData(skey, enc.asn1Encode(), KeyUsage.KU_TICKET)