提交 352e0c9d 编写于 作者: A asaha

Merge

...@@ -358,6 +358,7 @@ a21dd7999d1e4ba612c951c2c78504d23eb7243a jdk8u31-b11 ...@@ -358,6 +358,7 @@ a21dd7999d1e4ba612c951c2c78504d23eb7243a jdk8u31-b11
ced84cf3eebc69f7e04b0098d85dcb3a6b872586 jdk8u31-b31 ced84cf3eebc69f7e04b0098d85dcb3a6b872586 jdk8u31-b31
46338075c4262057099e57638e0758817052da0d jdk8u31-b32 46338075c4262057099e57638e0758817052da0d jdk8u31-b32
a1c3099e1b90230435e890ca56adc8a5aa5149ff jdk8u31-b33 a1c3099e1b90230435e890ca56adc8a5aa5149ff jdk8u31-b33
35dfb86684554685d6efd2fc7fd5eb9b7d4545c5 jdk8u31-b34
e6ed015afbbf3459ba3297e270b4f3170e989c80 jdk8u40-b00 e6ed015afbbf3459ba3297e270b4f3170e989c80 jdk8u40-b00
6e223d48080ef40f4ec11ecbcd19b4a20813b9eb jdk8u40-b01 6e223d48080ef40f4ec11ecbcd19b4a20813b9eb jdk8u40-b01
4797cd0713b44b009525f1276d571ade7e24f3f5 jdk8u40-b02 4797cd0713b44b009525f1276d571ade7e24f3f5 jdk8u40-b02
...@@ -429,6 +430,8 @@ b7403e15864dc0c1f9740d66af91bddb3e2215e8 jdk8u51-b14 ...@@ -429,6 +430,8 @@ b7403e15864dc0c1f9740d66af91bddb3e2215e8 jdk8u51-b14
192bda44c0c463104c96058bb815a546b282ca43 jdk8u51-b15 192bda44c0c463104c96058bb815a546b282ca43 jdk8u51-b15
ee86422973691bb7efae58d201e5a382ea0bb150 jdk8u51-b16 ee86422973691bb7efae58d201e5a382ea0bb150 jdk8u51-b16
f94ea276f608b22d78281d70361092ba4864038e jdk8u51-b31 f94ea276f608b22d78281d70361092ba4864038e jdk8u51-b31
887dde3afb3bb233958775de22eafb3328af6437 jdk8u51-b32
dc7b827522bc3a804f7e8951cc27414f19a7c427 jdk8u51-b33
5c31204d19e5976f025026db3d5c17331e8c44db jdk8u60-b00 5c31204d19e5976f025026db3d5c17331e8c44db jdk8u60-b00
c46daef6edb5385d11876ed40f292a4b62e96867 jdk8u60-b01 c46daef6edb5385d11876ed40f292a4b62e96867 jdk8u60-b01
c10fd784956cc7099657181029ac3e790267b678 jdk8u60-b02 c10fd784956cc7099657181029ac3e790267b678 jdk8u60-b02
...@@ -457,6 +460,8 @@ d433f5fd8910bee1f2c295b65cf03977034fe0ea jdk8u60-b24 ...@@ -457,6 +460,8 @@ d433f5fd8910bee1f2c295b65cf03977034fe0ea jdk8u60-b24
c8cfbe57bcd5042d2fef42dcef14d73dd4bdc416 jdk8u60-b25 c8cfbe57bcd5042d2fef42dcef14d73dd4bdc416 jdk8u60-b25
0d6a8a9b26a37678b420ff540b5a622c3f4fd44c jdk8u60-b26 0d6a8a9b26a37678b420ff540b5a622c3f4fd44c jdk8u60-b26
afbc08ea922bf6e5e14d2eea24a2f94f37627ea7 jdk8u60-b27 afbc08ea922bf6e5e14d2eea24a2f94f37627ea7 jdk8u60-b27
1450696a76c667e6f189d026408182a002b93fa7 jdk8u60-b31
fe24fa1e6d995390df6491975352a15634981b35 jdk8u60-b32
286b9a885fcc6245fdf2b20697473ec3b35f2538 jdk8u65-b00 286b9a885fcc6245fdf2b20697473ec3b35f2538 jdk8u65-b00
80a796d0db958f49a4b0713818227eda8e5efbb9 jdk8u65-b01 80a796d0db958f49a4b0713818227eda8e5efbb9 jdk8u65-b01
77d48e6d111faec236c8678997ae4311151cfee4 jdk8u65-b02 77d48e6d111faec236c8678997ae4311151cfee4 jdk8u65-b02
...@@ -489,6 +494,14 @@ e951c898bb6ca7be2ce49ac23f8442c0bccad4e9 jdk8u66-b13 ...@@ -489,6 +494,14 @@ e951c898bb6ca7be2ce49ac23f8442c0bccad4e9 jdk8u66-b13
ea602badedd0cd0c352c072220a884e8f1335e33 jdk8u66-b15 ea602badedd0cd0c352c072220a884e8f1335e33 jdk8u66-b15
5ceafca6a734e13d51319df6afd40678d68f9851 jdk8u66-b16 5ceafca6a734e13d51319df6afd40678d68f9851 jdk8u66-b16
e6d562c0f079dfd1e21c3734b2dca16f4b2e2494 jdk8u66-b17 e6d562c0f079dfd1e21c3734b2dca16f4b2e2494 jdk8u66-b17
f712dceafb546ea5833aeea507b5736e7e45f1ae jdk8u66-b31
9a2747ef337bdee71bc8225dea77eb403cca1179 jdk8u71-b00
e8b5e10a19d66a77d04f12d4677e6fec66f79651 jdk8u71-b01
25d689a73bc037e1710f95f6d4acf0671d22047d jdk8u71-b02
ab54163c8610f6238a1d5f1f67cbd19ba13d08a0 jdk8u71-b03
5ea62bb625b6b8f828098884d13eb2e3114a7c97 jdk8u71-b04
1a9ced1852957b65e0c156602c3101aff17274fb jdk8u71-b05
be9d91d310a02c2974d2bdabc31d8a6df8ad596e jdk8u71-b06
be5faa9c77042f202106c18f4e8ea211137b4a3b jdk8u72-b00 be5faa9c77042f202106c18f4e8ea211137b4a3b jdk8u72-b00
5ad1e9e8e8417f80c91d7e0f1f44cdf89b34ead3 jdk8u72-b01 5ad1e9e8e8417f80c91d7e0f1f44cdf89b34ead3 jdk8u72-b01
ab0c1040414d038ccbcfcc8ceb1ccf2f44ead8e4 jdk8u72-b02 ab0c1040414d038ccbcfcc8ceb1ccf2f44ead8e4 jdk8u72-b02
......
/* /*
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -234,6 +234,11 @@ public final class CPrinterJob extends RasterPrinterJob { ...@@ -234,6 +234,11 @@ public final class CPrinterJob extends RasterPrinterJob {
// this will not work if the user clicks on the "Preview" button // this will not work if the user clicks on the "Preview" button
// However if the printer is a StreamPrintService, its the right path. // However if the printer is a StreamPrintService, its the right path.
PrintService psvc = getPrintService(); PrintService psvc = getPrintService();
if (psvc == null) {
throw new PrinterException("No print service found.");
}
if (psvc instanceof StreamPrintService) { if (psvc instanceof StreamPrintService) {
spoolToService(psvc, attributes); spoolToService(psvc, attributes);
return; return;
...@@ -775,4 +780,4 @@ public final class CPrinterJob extends RasterPrinterJob { ...@@ -775,4 +780,4 @@ public final class CPrinterJob extends RasterPrinterJob {
(float) (paper.getImageableHeight() / dpi), (float) (paper.getImageableHeight() / dpi),
MediaPrintableArea.INCH); MediaPrintableArea.INCH);
} }
} }
\ No newline at end of file
/* /*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -263,7 +263,7 @@ abstract class PBES2Core extends CipherSpi { ...@@ -263,7 +263,7 @@ abstract class PBES2Core extends CipherSpi {
passwdChars[i] = (char) (passwdBytes[i] & 0x7f); passwdChars[i] = (char) (passwdBytes[i] & 0x7f);
PBEKeySpec pbeSpec = PBEKeySpec pbeSpec =
new PBEKeySpec(passwdChars, salt, iCount, blkSize * 8); new PBEKeySpec(passwdChars, salt, iCount, keyLength);
// password char[] was cloned in PBEKeySpec constructor, // password char[] was cloned in PBEKeySpec constructor,
// so we can zero it out here // so we can zero it out here
java.util.Arrays.fill(passwdChars, ' '); java.util.Arrays.fill(passwdChars, ' ');
......
...@@ -74,11 +74,14 @@ public final class TlsRsaPremasterSecretGenerator extends KeyGeneratorSpi { ...@@ -74,11 +74,14 @@ public final class TlsRsaPremasterSecretGenerator extends KeyGeneratorSpi {
"TlsRsaPremasterSecretGenerator must be initialized"); "TlsRsaPremasterSecretGenerator must be initialized");
} }
if (random == null) { byte[] b = spec.getEncodedSecret();
random = new SecureRandom(); if (b == null) {
if (random == null) {
random = new SecureRandom();
}
b = new byte[48];
random.nextBytes(b);
} }
byte[] b = new byte[48];
random.nextBytes(b);
b[0] = (byte)spec.getMajorVersion(); b[0] = (byte)spec.getMajorVersion();
b[1] = (byte)spec.getMinorVersion(); b[1] = (byte)spec.getMinorVersion();
......
/* /*
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,6 +27,10 @@ package java.net; ...@@ -27,6 +27,10 @@ package java.net;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.ObjectStreamField;
import java.io.ObjectInputStream.GetField;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import sun.security.util.SecurityConstants; import sun.security.util.SecurityConstants;
...@@ -135,6 +139,7 @@ import sun.security.util.SecurityConstants; ...@@ -135,6 +139,7 @@ import sun.security.util.SecurityConstants;
*/ */
public final class URL implements java.io.Serializable { public final class URL implements java.io.Serializable {
static final String BUILTIN_HANDLERS_PREFIX = "sun.net.www.protocol";
static final long serialVersionUID = -7627629688361524110L; static final long serialVersionUID = -7627629688361524110L;
/** /**
...@@ -219,6 +224,8 @@ public final class URL implements java.io.Serializable { ...@@ -219,6 +224,8 @@ public final class URL implements java.io.Serializable {
*/ */
private int hashCode = -1; private int hashCode = -1;
private transient UrlDeserializedState tempState;
/** /**
* Creates a {@code URL} object from the specified * Creates a {@code URL} object from the specified
* {@code protocol}, {@code host}, {@code port} * {@code protocol}, {@code host}, {@code port}
...@@ -1219,6 +1226,31 @@ public final class URL implements java.io.Serializable { ...@@ -1219,6 +1226,31 @@ public final class URL implements java.io.Serializable {
} }
/**
* @serialField protocol String
*
* @serialField host String
*
* @serialField port int
*
* @serialField authority String
*
* @serialField file String
*
* @serialField ref String
*
* @serialField hashCode int
*
*/
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("protocol", String.class),
new ObjectStreamField("host", String.class),
new ObjectStreamField("port", int.class),
new ObjectStreamField("authority", String.class),
new ObjectStreamField("file", String.class),
new ObjectStreamField("ref", String.class),
new ObjectStreamField("hashCode", int.class), };
/** /**
* WriteObject is called to save the state of the URL to an * WriteObject is called to save the state of the URL to an
* ObjectOutputStream. The handler is not saved since it is * ObjectOutputStream. The handler is not saved since it is
...@@ -1241,16 +1273,67 @@ public final class URL implements java.io.Serializable { ...@@ -1241,16 +1273,67 @@ public final class URL implements java.io.Serializable {
* stream handler. * stream handler.
*/ */
private synchronized void readObject(java.io.ObjectInputStream s) private synchronized void readObject(java.io.ObjectInputStream s)
throws IOException, ClassNotFoundException throws IOException, ClassNotFoundException {
{ GetField gf = s.readFields();
s.defaultReadObject(); // read the fields String protocol = (String)gf.get("protocol", null);
if ((handler = getURLStreamHandler(protocol)) == null) { if (getURLStreamHandler(protocol) == null) {
throw new IOException("unknown protocol: " + protocol); throw new IOException("unknown protocol: " + protocol);
} }
String host = (String)gf.get("host", null);
int port = gf.get("port", -1);
String authority = (String)gf.get("authority", null);
String file = (String)gf.get("file", null);
String ref = (String)gf.get("ref", null);
int hashCode = gf.get("hashCode", -1);
if (authority == null
&& ((host != null && host.length() > 0) || port != -1)) {
if (host == null)
host = "";
authority = (port == -1) ? host : host + ":" + port;
}
tempState = new UrlDeserializedState(protocol, host, port, authority,
file, ref, hashCode);
}
/**
* Replaces the de-serialized object with an URL object.
*
* @return a newly created object from the deserialzed state.
*
* @throws ObjectStreamException if a new object replacing this
* object could not be created
*/
private Object readResolve() throws ObjectStreamException {
URLStreamHandler handler = null;
// already been checked in readObject
handler = getURLStreamHandler(tempState.getProtocol());
URL replacementURL = null;
if (isBuiltinStreamHandler(handler.getClass().getName())) {
replacementURL = fabricateNewURL();
} else {
replacementURL = setDeserializedFields(handler);
}
return replacementURL;
}
private URL setDeserializedFields(URLStreamHandler handler) {
URL replacementURL;
String userInfo = null;
String protocol = tempState.getProtocol();
String host = tempState.getHost();
int port = tempState.getPort();
String authority = tempState.getAuthority();
String file = tempState.getFile();
String ref = tempState.getRef();
int hashCode = tempState.getHashCode();
// Construct authority part // Construct authority part
if (authority == null && if (authority == null
((host != null && host.length() > 0) || port != -1)) { && ((host != null && host.length() > 0) || port != -1)) {
if (host == null) if (host == null)
host = ""; host = "";
authority = (port == -1) ? host : host + ":" + port; authority = (port == -1) ? host : host + ":" + port;
...@@ -1269,8 +1352,8 @@ public final class URL implements java.io.Serializable { ...@@ -1269,8 +1352,8 @@ public final class URL implements java.io.Serializable {
} }
// Construct path and query part // Construct path and query part
path = null; String path = null;
query = null; String query = null;
if (file != null) { if (file != null) {
// Fix: only do this if hierarchical? // Fix: only do this if hierarchical?
int q = file.lastIndexOf('?'); int q = file.lastIndexOf('?');
...@@ -1280,6 +1363,67 @@ public final class URL implements java.io.Serializable { ...@@ -1280,6 +1363,67 @@ public final class URL implements java.io.Serializable {
} else } else
path = file; path = file;
} }
if (port == -1) {
port = 0;
}
// Set the object fields.
this.protocol = protocol;
this.host = host;
this.port = port;
this.file = file;
this.authority = authority;
this.ref = ref;
this.hashCode = hashCode;
this.handler = handler;
this.query = query;
this.path = path;
this.userInfo = userInfo;
replacementURL = this;
return replacementURL;
}
private URL fabricateNewURL()
throws InvalidObjectException {
// create URL string from deserialized object
URL replacementURL = null;
String urlString = tempState.reconstituteUrlString();
try {
replacementURL = new URL(urlString);
} catch (MalformedURLException mEx) {
resetState();
InvalidObjectException invoEx = new InvalidObjectException(
"Malformed URL: " + urlString);
invoEx.initCause(mEx);
throw invoEx;
}
replacementURL.setSerializedHashCode(tempState.getHashCode());
resetState();
return replacementURL;
}
private boolean isBuiltinStreamHandler(String handlerClassName) {
return (handlerClassName.startsWith(BUILTIN_HANDLERS_PREFIX));
}
private void resetState() {
this.protocol = null;
this.host = null;
this.port = -1;
this.file = null;
this.authority = null;
this.ref = null;
this.hashCode = -1;
this.handler = null;
this.query = null;
this.path = null;
this.userInfo = null;
this.tempState = null;
}
private void setSerializedHashCode(int hc) {
this.hashCode = hc;
} }
} }
...@@ -1311,3 +1455,82 @@ class Parts { ...@@ -1311,3 +1455,82 @@ class Parts {
return ref; return ref;
} }
} }
final class UrlDeserializedState {
private final String protocol;
private final String host;
private final int port;
private final String authority;
private final String file;
private final String ref;
private final int hashCode;
public UrlDeserializedState(String protocol,
String host, int port,
String authority, String file,
String ref, int hashCode) {
this.protocol = protocol;
this.host = host;
this.port = port;
this.authority = authority;
this.file = file;
this.ref = ref;
this.hashCode = hashCode;
}
String getProtocol() {
return protocol;
}
String getHost() {
return host;
}
String getAuthority () {
return authority;
}
int getPort() {
return port;
}
String getFile () {
return file;
}
String getRef () {
return ref;
}
int getHashCode () {
return hashCode;
}
String reconstituteUrlString() {
// pre-compute length of StringBuilder
int len = protocol.length() + 1;
if (authority != null && authority.length() > 0)
len += 2 + authority.length();
if (file != null) {
len += file.length();
}
if (ref != null)
len += 1 + ref.length();
StringBuilder result = new StringBuilder(len);
result.append(protocol);
result.append(":");
if (authority != null && authority.length() > 0) {
result.append("//");
result.append(authority);
}
if (file != null) {
result.append(file);
}
if (ref != null) {
result.append("#");
result.append(ref);
}
return result.toString();
}
}
...@@ -361,7 +361,6 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced { ...@@ -361,7 +361,6 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
"connectionId=" + connectionId "connectionId=" + connectionId
+", className=" + className +", className=" + className
+", name=" + name +", name=" + name
+", params=" + objects(values)
+", signature=" + strings(signature)); +", signature=" + strings(signature));
return (ObjectInstance) return (ObjectInstance)
...@@ -427,7 +426,6 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced { ...@@ -427,7 +426,6 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
+", className=" + className +", className=" + className
+", name=" + name +", name=" + name
+", loaderName=" + loaderName +", loaderName=" + loaderName
+", params=" + objects(values)
+", signature=" + strings(signature)); +", signature=" + strings(signature));
return (ObjectInstance) return (ObjectInstance)
...@@ -719,7 +717,7 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced { ...@@ -719,7 +717,7 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
if (debug) logger.debug("setAttribute", if (debug) logger.debug("setAttribute",
"connectionId=" + connectionId "connectionId=" + connectionId
+", name="+name +", name="+name
+", attribute="+attr); +", attribute name="+attr.getName());
doPrivilegedOperation( doPrivilegedOperation(
SET_ATTRIBUTE, SET_ATTRIBUTE,
...@@ -770,7 +768,7 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced { ...@@ -770,7 +768,7 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
if (debug) logger.debug("setAttributes", if (debug) logger.debug("setAttributes",
"connectionId=" + connectionId "connectionId=" + connectionId
+", name="+name +", name="+name
+", attributes="+attrlist); +", attribute names="+RMIConnector.getAttributesNames(attrlist));
return (AttributeList) return (AttributeList)
doPrivilegedOperation( doPrivilegedOperation(
...@@ -825,7 +823,6 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced { ...@@ -825,7 +823,6 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
"connectionId=" + connectionId "connectionId=" + connectionId
+", name="+name +", name="+name
+", operationName="+operationName +", operationName="+operationName
+", params="+objects(values)
+", signature="+strings(signature)); +", signature="+strings(signature));
return return
......
...@@ -41,7 +41,6 @@ import java.io.NotSerializableException; ...@@ -41,7 +41,6 @@ import java.io.NotSerializableException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectStreamClass; import java.io.ObjectStreamClass;
import java.io.Serializable; import java.io.Serializable;
import java.io.WriteAbortedException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
...@@ -70,6 +69,7 @@ import java.util.Map; ...@@ -70,6 +69,7 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.stream.Collectors;
import javax.management.Attribute; import javax.management.Attribute;
import javax.management.AttributeList; import javax.management.AttributeList;
import javax.management.AttributeNotFoundException; import javax.management.AttributeNotFoundException;
...@@ -712,9 +712,7 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable ...@@ -712,9 +712,7 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable
if (logger.debugOn()) if (logger.debugOn())
logger.debug("createMBean(String,ObjectName,Object[],String[])", logger.debug("createMBean(String,ObjectName,Object[],String[])",
"className=" + className + ", name=" "className=" + className + ", name="
+ name + ", params=" + name + ", signature=" + strings(signature));
+ objects(params) + ", signature="
+ strings(signature));
final MarshalledObject<Object[]> sParams = final MarshalledObject<Object[]> sParams =
new MarshalledObject<Object[]>(params); new MarshalledObject<Object[]>(params);
...@@ -753,8 +751,7 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable ...@@ -753,8 +751,7 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable
if (logger.debugOn()) logger.debug( if (logger.debugOn()) logger.debug(
"createMBean(String,ObjectName,ObjectName,Object[],String[])", "createMBean(String,ObjectName,ObjectName,Object[],String[])",
"className=" + className + ", name=" + name + ", loaderName=" "className=" + className + ", name=" + name + ", loaderName="
+ loaderName + ", params=" + objects(params) + loaderName + ", signature=" + strings(signature));
+ ", signature=" + strings(signature));
final MarshalledObject<Object[]> sParams = final MarshalledObject<Object[]> sParams =
new MarshalledObject<Object[]>(params); new MarshalledObject<Object[]>(params);
...@@ -954,8 +951,8 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable ...@@ -954,8 +951,8 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable
IOException { IOException {
if (logger.debugOn()) logger.debug("setAttribute", if (logger.debugOn()) logger.debug("setAttribute",
"name=" + name + ", attribute=" "name=" + name + ", attribute name="
+ attribute); + attribute.getName());
final MarshalledObject<Attribute> sAttribute = final MarshalledObject<Attribute> sAttribute =
new MarshalledObject<Attribute>(attribute); new MarshalledObject<Attribute>(attribute);
...@@ -977,9 +974,11 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable ...@@ -977,9 +974,11 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable
ReflectionException, ReflectionException,
IOException { IOException {
if (logger.debugOn()) logger.debug("setAttributes", if (logger.debugOn()) {
"name=" + name + ", attributes=" logger.debug("setAttributes",
+ attributes); "name=" + name + ", attribute names="
+ getAttributesNames(attributes));
}
final MarshalledObject<AttributeList> sAttributes = final MarshalledObject<AttributeList> sAttributes =
new MarshalledObject<AttributeList>(attributes); new MarshalledObject<AttributeList>(attributes);
...@@ -1012,7 +1011,6 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable ...@@ -1012,7 +1011,6 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable
if (logger.debugOn()) logger.debug("invoke", if (logger.debugOn()) logger.debug("invoke",
"name=" + name "name=" + name
+ ", operationName=" + operationName + ", operationName=" + operationName
+ ", params=" + objects(params)
+ ", signature=" + strings(signature)); + ", signature=" + strings(signature));
final MarshalledObject<Object[]> sParams = final MarshalledObject<Object[]> sParams =
...@@ -2636,4 +2634,12 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable ...@@ -2636,4 +2634,12 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable
private static String strings(final String[] strs) { private static String strings(final String[] strs) {
return objects(strs); return objects(strs);
} }
static String getAttributesNames(AttributeList attributes) {
return attributes != null ?
attributes.asList().stream()
.map(Attribute::getName)
.collect(Collectors.joining("[", ", ", "]"))
: "[]";
}
} }
...@@ -102,17 +102,13 @@ class GarbageCollectorImpl extends MemoryManagerImpl ...@@ -102,17 +102,13 @@ class GarbageCollectorImpl extends MemoryManagerImpl
GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION
}; };
private MBeanNotificationInfo[] notifInfo = null; @Override
public MBeanNotificationInfo[] getNotificationInfo() { public MBeanNotificationInfo[] getNotificationInfo() {
synchronized (this) { return new MBeanNotificationInfo[]{
if (notifInfo == null) { new MBeanNotificationInfo(gcNotifTypes,
notifInfo = new MBeanNotificationInfo[1]; notifName,
notifInfo[0] = new MBeanNotificationInfo(gcNotifTypes, "GC Notification")
notifName, };
"GC Notification");
}
}
return notifInfo;
} }
private static long seqNumber = 0; private static long seqNumber = 0;
......
...@@ -115,17 +115,10 @@ class MemoryImpl extends NotificationEmitterSupport ...@@ -115,17 +115,10 @@ class MemoryImpl extends NotificationEmitterSupport
"Memory usage exceeds collection usage threshold" "Memory usage exceeds collection usage threshold"
}; };
private MBeanNotificationInfo[] notifInfo = null;
public MBeanNotificationInfo[] getNotificationInfo() { public MBeanNotificationInfo[] getNotificationInfo() {
synchronized (this) { return new MBeanNotificationInfo[] {
if (notifInfo == null) { new MBeanNotificationInfo(notifTypes, notifName, "Memory Notification")
notifInfo = new MBeanNotificationInfo[1]; };
notifInfo[0] = new MBeanNotificationInfo(notifTypes,
notifName,
"Memory Notification");
}
}
return notifInfo;
} }
private static String getNotifMsg(String notifType) { private static String getNotifMsg(String notifType) {
......
...@@ -43,6 +43,8 @@ import java.security.PrivilegedAction; ...@@ -43,6 +43,8 @@ import java.security.PrivilegedAction;
public class TlsRsaPremasterSecretParameterSpec public class TlsRsaPremasterSecretParameterSpec
implements AlgorithmParameterSpec { implements AlgorithmParameterSpec {
private final byte[] encodedSecret;
/* /*
* The TLS spec says that the version in the RSA premaster secret must * The TLS spec says that the version in the RSA premaster secret must
* be the maximum version supported by the client (i.e. the version it * be the maximum version supported by the client (i.e. the version it
...@@ -89,6 +91,33 @@ public class TlsRsaPremasterSecretParameterSpec ...@@ -89,6 +91,33 @@ public class TlsRsaPremasterSecretParameterSpec
this.clientVersion = checkVersion(clientVersion); this.clientVersion = checkVersion(clientVersion);
this.serverVersion = checkVersion(serverVersion); this.serverVersion = checkVersion(serverVersion);
this.encodedSecret = null;
}
/**
* Constructs a new TlsRsaPremasterSecretParameterSpec.
*
* @param clientVersion the version of the TLS protocol by which the
* client wishes to communicate during this session
* @param serverVersion the negotiated version of the TLS protocol which
* contains the lower of that suggested by the client in the client
* hello and the highest supported by the server.
* @param encodedSecret the encoded secret key
*
* @throws IllegalArgumentException if clientVersion or serverVersion are
* negative or larger than (2^16 - 1) or if encodedSecret is not
* exactly 48 bytes
*/
public TlsRsaPremasterSecretParameterSpec(
int clientVersion, int serverVersion, byte[] encodedSecret) {
this.clientVersion = checkVersion(clientVersion);
this.serverVersion = checkVersion(serverVersion);
if (encodedSecret == null || encodedSecret.length != 48) {
throw new IllegalArgumentException(
"Encoded secret is not exactly 48 bytes");
}
this.encodedSecret = encodedSecret.clone();
} }
/** /**
...@@ -147,4 +176,13 @@ public class TlsRsaPremasterSecretParameterSpec ...@@ -147,4 +176,13 @@ public class TlsRsaPremasterSecretParameterSpec
} }
return version; return version;
} }
/**
* Returns the encoded secret.
*
* @return the encoded secret, may be null if no encoded secret.
*/
public byte[] getEncodedSecret() {
return encodedSecret == null ? null : encodedSecret.clone();
}
} }
/* /*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -41,12 +41,6 @@ public final class JCAUtil { ...@@ -41,12 +41,6 @@ public final class JCAUtil {
// no instantiation // no instantiation
} }
// lock to use for synchronization
private static final Object LOCK = JCAUtil.class;
// cached SecureRandom instance
private static volatile SecureRandom secureRandom;
// size of the temporary arrays we use. Should fit into the CPU's 1st // size of the temporary arrays we use. Should fit into the CPU's 1st
// level cache and could be adjusted based on the platform // level cache and could be adjusted based on the platform
private final static int ARRAY_SIZE = 4096; private final static int ARRAY_SIZE = 4096;
...@@ -60,26 +54,19 @@ public final class JCAUtil { ...@@ -60,26 +54,19 @@ public final class JCAUtil {
return Math.min(ARRAY_SIZE, totalSize); return Math.min(ARRAY_SIZE, totalSize);
} }
// cached SecureRandom instance
private static class CachedSecureRandomHolder {
public static SecureRandom instance = new SecureRandom();
}
/** /**
* Get a SecureRandom instance. This method should me used by JDK * Get a SecureRandom instance. This method should be used by JDK
* internal code in favor of calling "new SecureRandom()". That needs to * internal code in favor of calling "new SecureRandom()". That needs to
* iterate through the provider table to find the default SecureRandom * iterate through the provider table to find the default SecureRandom
* implementation, which is fairly inefficient. * implementation, which is fairly inefficient.
*/ */
public static SecureRandom getSecureRandom() { public static SecureRandom getSecureRandom() {
// we use double checked locking to minimize synchronization return CachedSecureRandomHolder.instance;
// works because we use a volatile reference
SecureRandom r = secureRandom;
if (r == null) {
synchronized (LOCK) {
r = secureRandom;
if (r == null) {
r = new SecureRandom();
secureRandom = r;
}
}
}
return r;
} }
} }
...@@ -35,6 +35,7 @@ import javax.crypto.*; ...@@ -35,6 +35,7 @@ import javax.crypto.*;
import javax.crypto.spec.*; import javax.crypto.spec.*;
import sun.nio.ch.DirectBuffer; import sun.nio.ch.DirectBuffer;
import sun.security.jca.JCAUtil;
import sun.security.pkcs11.wrapper.*; import sun.security.pkcs11.wrapper.*;
import static sun.security.pkcs11.wrapper.PKCS11Constants.*; import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
...@@ -379,7 +380,7 @@ final class P11Cipher extends CipherSpi { ...@@ -379,7 +380,7 @@ final class P11Cipher extends CipherSpi {
} }
// generate random IV // generate random IV
if (random == null) { if (random == null) {
random = new SecureRandom(); random = JCAUtil.getSecureRandom();
} }
iv = new byte[blockSize]; iv = new byte[blockSize];
random.nextBytes(iv); random.nextBytes(iv);
......
...@@ -468,49 +468,49 @@ final class P11RSACipher extends CipherSpi { ...@@ -468,49 +468,49 @@ final class P11RSACipher extends CipherSpi {
algorithm.equals("TlsRsaPremasterSecret"); algorithm.equals("TlsRsaPremasterSecret");
Exception failover = null; Exception failover = null;
SecureRandom secureRandom = random;
if (secureRandom == null && isTlsRsaPremasterSecret) {
secureRandom = new SecureRandom();
}
// Should C_Unwrap be preferred for non-TLS RSA premaster secret? // Should C_Unwrap be preferred for non-TLS RSA premaster secret?
if (token.supportsRawSecretKeyImport()) { if (token.supportsRawSecretKeyImport()) {
// XXX implement unwrap using C_Unwrap() for all keys // XXX implement unwrap using C_Unwrap() for all keys
implInit(Cipher.DECRYPT_MODE, p11Key); implInit(Cipher.DECRYPT_MODE, p11Key);
if (wrappedKey.length > maxInputSize) {
throw new InvalidKeyException("Key is too long for unwrapping");
}
byte[] encoded = null;
implUpdate(wrappedKey, 0, wrappedKey.length);
try { try {
encoded = doFinal(); if (wrappedKey.length > maxInputSize) {
} catch (BadPaddingException e) { throw new InvalidKeyException("Key is too long for unwrapping");
if (isTlsRsaPremasterSecret) { }
failover = e;
} else { byte[] encoded = null;
implUpdate(wrappedKey, 0, wrappedKey.length);
try {
encoded = doFinal();
} catch (BadPaddingException e) {
if (isTlsRsaPremasterSecret) {
failover = e;
} else {
throw new InvalidKeyException("Unwrapping failed", e);
}
} catch (IllegalBlockSizeException e) {
// should not occur, handled with length check above
throw new InvalidKeyException("Unwrapping failed", e); throw new InvalidKeyException("Unwrapping failed", e);
} }
} catch (IllegalBlockSizeException e) {
// should not occur, handled with length check above
throw new InvalidKeyException("Unwrapping failed", e);
}
if (isTlsRsaPremasterSecret) { if (isTlsRsaPremasterSecret) {
if (!(spec instanceof TlsRsaPremasterSecretParameterSpec)) { if (!(spec instanceof TlsRsaPremasterSecretParameterSpec)) {
throw new IllegalStateException( throw new IllegalStateException(
"No TlsRsaPremasterSecretParameterSpec specified"); "No TlsRsaPremasterSecretParameterSpec specified");
}
// polish the TLS premaster secret
TlsRsaPremasterSecretParameterSpec psps =
(TlsRsaPremasterSecretParameterSpec)spec;
encoded = KeyUtil.checkTlsPreMasterSecretKey(
psps.getClientVersion(), psps.getServerVersion(),
random, encoded, (failover != null));
} }
// polish the TLS premaster secret return ConstructKeys.constructKey(encoded, algorithm, type);
TlsRsaPremasterSecretParameterSpec psps = } finally {
(TlsRsaPremasterSecretParameterSpec)spec; // Restore original mode
encoded = KeyUtil.checkTlsPreMasterSecretKey( implInit(Cipher.UNWRAP_MODE, p11Key);
psps.getClientVersion(), psps.getServerVersion(),
secureRandom, encoded, (failover != null));
} }
return ConstructKeys.constructKey(encoded, algorithm, type);
} else { } else {
Session s = null; Session s = null;
SecretKey secretKey = null; SecretKey secretKey = null;
...@@ -538,20 +538,13 @@ final class P11RSACipher extends CipherSpi { ...@@ -538,20 +538,13 @@ final class P11RSACipher extends CipherSpi {
} }
if (isTlsRsaPremasterSecret) { if (isTlsRsaPremasterSecret) {
byte[] replacer = new byte[48];
if (failover == null) {
// Does smart compiler dispose this operation?
secureRandom.nextBytes(replacer);
}
TlsRsaPremasterSecretParameterSpec psps = TlsRsaPremasterSecretParameterSpec psps =
(TlsRsaPremasterSecretParameterSpec)spec; (TlsRsaPremasterSecretParameterSpec)spec;
// Please use the tricky failover and replacer byte array // Please use the tricky failover as the parameter so that
// as the parameters so that smart compiler won't dispose // smart compiler won't dispose the unused variable.
// the unused variable .
secretKey = polishPreMasterSecretKey(token, s, secretKey = polishPreMasterSecretKey(token, s,
failover, replacer, secretKey, failover, secretKey,
psps.getClientVersion(), psps.getServerVersion()); psps.getClientVersion(), psps.getServerVersion());
} }
...@@ -570,29 +563,27 @@ final class P11RSACipher extends CipherSpi { ...@@ -570,29 +563,27 @@ final class P11RSACipher extends CipherSpi {
private static SecretKey polishPreMasterSecretKey( private static SecretKey polishPreMasterSecretKey(
Token token, Session session, Token token, Session session,
Exception failover, byte[] replacer, SecretKey secretKey, Exception failover, SecretKey unwrappedKey,
int clientVersion, int serverVersion) { int clientVersion, int serverVersion) {
if (failover != null) { SecretKey newKey;
CK_VERSION version = new CK_VERSION( CK_VERSION version = new CK_VERSION(
(clientVersion >>> 8) & 0xFF, clientVersion & 0xFF); (clientVersion >>> 8) & 0xFF, clientVersion & 0xFF);
try { try {
CK_ATTRIBUTE[] attributes = token.getAttributes( CK_ATTRIBUTE[] attributes = token.getAttributes(
O_GENERATE, CKO_SECRET_KEY, O_GENERATE, CKO_SECRET_KEY,
CKK_GENERIC_SECRET, new CK_ATTRIBUTE[0]); CKK_GENERIC_SECRET, new CK_ATTRIBUTE[0]);
long keyID = token.p11.C_GenerateKey(session.id(), long keyID = token.p11.C_GenerateKey(session.id(),
// new CK_MECHANISM(CKM_TLS_PRE_MASTER_KEY_GEN, version), new CK_MECHANISM(CKM_SSL3_PRE_MASTER_KEY_GEN, version),
new CK_MECHANISM(CKM_SSL3_PRE_MASTER_KEY_GEN, version), attributes);
attributes); newKey = P11Key.secretKey(session,
return P11Key.secretKey(session, keyID, "TlsRsaPremasterSecret", 48 << 3, attributes);
keyID, "TlsRsaPremasterSecret", 48 << 3, attributes); } catch (PKCS11Exception e) {
} catch (PKCS11Exception e) { throw new ProviderException(
throw new ProviderException( "Could not generate premaster secret", e);
"Could not generate premaster secret", e);
}
} }
return secretKey; return (failover == null) ? unwrappedKey : newKey;
} }
} }
......
...@@ -111,14 +111,34 @@ final class RSAClientKeyExchange extends HandshakeMessage { ...@@ -111,14 +111,34 @@ final class RSAClientKeyExchange extends HandshakeMessage {
} }
} }
byte[] encoded = null;
try { try {
Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1); Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
cipher.init(Cipher.UNWRAP_MODE, privateKey, boolean needFailover = !KeyUtil.isOracleJCEProvider(
new TlsRsaPremasterSecretParameterSpec( cipher.getProvider().getName());
maxVersion.v, currentVersion.v), if (needFailover) {
generator); cipher.init(Cipher.DECRYPT_MODE, privateKey);
preMaster = (SecretKey)cipher.unwrap(encrypted, boolean failed = false;
"TlsRsaPremasterSecret", Cipher.SECRET_KEY); try {
encoded = cipher.doFinal(encrypted);
} catch (BadPaddingException bpe) {
// Note: encoded == null
failed = true;
}
encoded = KeyUtil.checkTlsPreMasterSecretKey(
maxVersion.v, currentVersion.v,
generator, encoded, failed);
preMaster = generatePreMasterSecret(
maxVersion.v, currentVersion.v,
encoded, generator);
} else {
cipher.init(Cipher.UNWRAP_MODE, privateKey,
new TlsRsaPremasterSecretParameterSpec(
maxVersion.v, currentVersion.v),
generator);
preMaster = (SecretKey)cipher.unwrap(encrypted,
"TlsRsaPremasterSecret", Cipher.SECRET_KEY);
}
} catch (InvalidKeyException ibk) { } catch (InvalidKeyException ibk) {
// the message is too big to process with RSA // the message is too big to process with RSA
throw new SSLProtocolException( throw new SSLProtocolException(
...@@ -133,6 +153,35 @@ final class RSAClientKeyExchange extends HandshakeMessage { ...@@ -133,6 +153,35 @@ final class RSAClientKeyExchange extends HandshakeMessage {
} }
} }
// generate a premaster secret with the specified version number
@SuppressWarnings("deprecation")
private static SecretKey generatePreMasterSecret(
int clientVersion, int serverVersion,
byte[] encodedSecret, SecureRandom generator) {
if (debug != null && Debug.isOn("handshake")) {
System.out.println("Generating a premaster secret");
}
try {
String s = ((clientVersion >= ProtocolVersion.TLS12.v) ?
"SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
KeyGenerator kg = JsseJce.getKeyGenerator(s);
kg.init(new TlsRsaPremasterSecretParameterSpec(
clientVersion, serverVersion, encodedSecret),
generator);
return kg.generateKey();
} catch (InvalidAlgorithmParameterException |
NoSuchAlgorithmException iae) {
// unlikely to happen, otherwise, must be a provider exception
if (debug != null && Debug.isOn("handshake")) {
System.out.println("RSA premaster secret generation error:");
iae.printStackTrace(System.out);
}
throw new RuntimeException("Could not generate premaster secret", iae);
}
}
@Override @Override
int messageType() { int messageType() {
return ht_client_key_exchange; return ht_client_key_exchange;
......
/* /*
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -41,6 +41,8 @@ import javax.crypto.spec.DHParameterSpec; ...@@ -41,6 +41,8 @@ import javax.crypto.spec.DHParameterSpec;
import javax.crypto.spec.DHPublicKeySpec; import javax.crypto.spec.DHPublicKeySpec;
import java.math.BigInteger; import java.math.BigInteger;
import sun.security.jca.JCAUtil;
/** /**
* A utility class to get key length, valiate keys, etc. * A utility class to get key length, valiate keys, etc.
*/ */
...@@ -144,8 +146,6 @@ public final class KeyUtil { ...@@ -144,8 +146,6 @@ public final class KeyUtil {
/** /**
* Returns whether the specified provider is Oracle provider or not. * Returns whether the specified provider is Oracle provider or not.
* <P>
* Note that this method is only apply to SunJCE and SunPKCS11 at present.
* *
* @param providerName * @param providerName
* the provider name * the provider name
...@@ -153,8 +153,11 @@ public final class KeyUtil { ...@@ -153,8 +153,11 @@ public final class KeyUtil {
* {@code providerName} is Oracle provider * {@code providerName} is Oracle provider
*/ */
public static final boolean isOracleJCEProvider(String providerName) { public static final boolean isOracleJCEProvider(String providerName) {
return providerName != null && (providerName.equals("SunJCE") || return providerName != null &&
providerName.startsWith("SunPKCS11")); (providerName.equals("SunJCE") ||
providerName.equals("SunMSCAPI") ||
providerName.equals("OracleUcrypto") ||
providerName.startsWith("SunPKCS11"));
} }
/** /**
...@@ -199,7 +202,7 @@ public final class KeyUtil { ...@@ -199,7 +202,7 @@ public final class KeyUtil {
byte[] encoded, boolean isFailOver) { byte[] encoded, boolean isFailOver) {
if (random == null) { if (random == null) {
random = new SecureRandom(); random = JCAUtil.getSecureRandom();
} }
byte[] replacer = new byte[48]; byte[] replacer = new byte[48];
random.nextBytes(replacer); random.nextBytes(replacer);
......
...@@ -588,7 +588,7 @@ public class AlgorithmId implements Serializable, DerEncoder { ...@@ -588,7 +588,7 @@ public class AlgorithmId implements Serializable, DerEncoder {
} }
if (oidTable == null) { if (oidTable == null) {
oidTable = new HashMap<String,ObjectIdentifier>(1); oidTable = Collections.<String,ObjectIdentifier>emptyMap();
} }
initOidTable = true; initOidTable = true;
} }
......
...@@ -29,6 +29,7 @@ import java.io.IOException; ...@@ -29,6 +29,7 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.*; import java.util.*;
import java.util.Collections;
import sun.security.util.DerOutputStream; import sun.security.util.DerOutputStream;
import sun.security.util.DerValue; import sun.security.util.DerValue;
...@@ -255,11 +256,12 @@ public class CRLDistributionPointsExtension extends Extension ...@@ -255,11 +256,12 @@ public class CRLDistributionPointsExtension extends Extension
*/ */
public void delete(String name) throws IOException { public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(POINTS)) { if (name.equalsIgnoreCase(POINTS)) {
distributionPoints = new ArrayList<DistributionPoint>(); distributionPoints =
Collections.<DistributionPoint>emptyList();
} else { } else {
throw new IOException("Attribute name [" + name + throw new IOException("Attribute name [" + name +
"] not recognized by " + "] not recognized by " +
"CertAttrSet:" + extensionName + "."); "CertAttrSet:" + extensionName + '.');
} }
encodeThis(); encodeThis();
} }
......
...@@ -157,11 +157,10 @@ implements CertAttrSet<String> { ...@@ -157,11 +157,10 @@ implements CertAttrSet<String> {
*/ */
public BigInteger get(String name) throws IOException { public BigInteger get(String name) throws IOException {
if (name.equalsIgnoreCase(NUMBER)) { if (name.equalsIgnoreCase(NUMBER)) {
if (crlNumber == null) return null; return crlNumber;
else return crlNumber;
} else { } else {
throw new IOException("Attribute name not recognized by" throw new IOException("Attribute name not recognized by" +
+ " CertAttrSet:" + extensionName + "."); " CertAttrSet:" + extensionName + '.');
} }
} }
......
...@@ -232,15 +232,15 @@ public class DNSName implements GeneralNameInterface { ...@@ -232,15 +232,15 @@ public class DNSName implements GeneralNameInterface {
* @throws UnsupportedOperationException if not supported for this name type * @throws UnsupportedOperationException if not supported for this name type
*/ */
public int subtreeDepth() throws UnsupportedOperationException { public int subtreeDepth() throws UnsupportedOperationException {
String subtree=name; // subtree depth is always at least 1
int i=1; int sum = 1;
/* count dots */ // count dots
for (; subtree.lastIndexOf('.') >= 0; i++) { for (int i = name.indexOf('.'); i >= 0; i = name.indexOf('.', i + 1)) {
subtree=subtree.substring(0,subtree.lastIndexOf('.')); ++sum;
} }
return i; return sum;
} }
} }
...@@ -197,7 +197,7 @@ public class EDIPartyName implements GeneralNameInterface { ...@@ -197,7 +197,7 @@ public class EDIPartyName implements GeneralNameInterface {
*/ */
public int hashCode() { public int hashCode() {
if (myhash == -1) { if (myhash == -1) {
myhash = 37 + party.hashCode(); myhash = 37 + (party == null ? 1 : party.hashCode());
if (assigner != null) { if (assigner != null) {
myhash = 37 * myhash + assigner.hashCode(); myhash = 37 * myhash + assigner.hashCode();
} }
......
...@@ -191,7 +191,7 @@ public class GeneralSubtrees implements Cloneable { ...@@ -191,7 +191,7 @@ public class GeneralSubtrees implements Cloneable {
// the list: if any subsequent entry matches or widens entry n, // the list: if any subsequent entry matches or widens entry n,
// remove entry n. If any subsequent entries narrow entry n, remove // remove entry n. If any subsequent entries narrow entry n, remove
// the subsequent entries. // the subsequent entries.
for (int i = 0; i < size(); i++) { for (int i = 0; i < (size() - 1); i++) {
GeneralNameInterface current = getGeneralNameInterface(i); GeneralNameInterface current = getGeneralNameInterface(i);
boolean remove1 = false; boolean remove1 = false;
......
...@@ -197,8 +197,10 @@ public class IPAddressName implements GeneralNameInterface { ...@@ -197,8 +197,10 @@ public class IPAddressName implements GeneralNameInterface {
// append a mask corresponding to the num of prefix bits specified // append a mask corresponding to the num of prefix bits specified
int prefixLen = Integer.parseInt(name.substring(slashNdx+1)); int prefixLen = Integer.parseInt(name.substring(slashNdx+1));
if (prefixLen > 128) if (prefixLen < 0 || prefixLen > 128) {
throw new IOException("IPv6Address prefix is longer than 128"); throw new IOException("IPv6Address prefix length (" +
prefixLen + ") in out of valid range [0,128]");
}
// create new bit array initialized to zeros // create new bit array initialized to zeros
BitArray bitArray = new BitArray(MASKSIZE * 8); BitArray bitArray = new BitArray(MASKSIZE * 8);
...@@ -317,7 +319,8 @@ public class IPAddressName implements GeneralNameInterface { ...@@ -317,7 +319,8 @@ public class IPAddressName implements GeneralNameInterface {
if (!(obj instanceof IPAddressName)) if (!(obj instanceof IPAddressName))
return false; return false;
byte[] other = ((IPAddressName)obj).getBytes(); IPAddressName otherName = (IPAddressName)obj;
byte[] other = otherName.address;
if (other.length != address.length) if (other.length != address.length)
return false; return false;
...@@ -326,12 +329,10 @@ public class IPAddressName implements GeneralNameInterface { ...@@ -326,12 +329,10 @@ public class IPAddressName implements GeneralNameInterface {
// Two subnet addresses // Two subnet addresses
// Mask each and compare masked values // Mask each and compare masked values
int maskLen = address.length/2; int maskLen = address.length/2;
byte[] maskedThis = new byte[maskLen];
byte[] maskedOther = new byte[maskLen];
for (int i=0; i < maskLen; i++) { for (int i=0; i < maskLen; i++) {
maskedThis[i] = (byte)(address[i] & address[i+maskLen]); byte maskedThis = (byte)(address[i] & address[i+maskLen]);
maskedOther[i] = (byte)(other[i] & other[i+maskLen]); byte maskedOther = (byte)(other[i] & other[i+maskLen]);
if (maskedThis[i] != maskedOther[i]) { if (maskedThis != maskedOther) {
return false; return false;
} }
} }
...@@ -400,7 +401,8 @@ public class IPAddressName implements GeneralNameInterface { ...@@ -400,7 +401,8 @@ public class IPAddressName implements GeneralNameInterface {
else if (((IPAddressName)inputName).equals(this)) else if (((IPAddressName)inputName).equals(this))
constraintType = NAME_MATCH; constraintType = NAME_MATCH;
else { else {
byte[] otherAddress = ((IPAddressName)inputName).getBytes(); IPAddressName otherName = (IPAddressName)inputName;
byte[] otherAddress = otherName.address;
if (otherAddress.length == 4 && address.length == 4) if (otherAddress.length == 4 && address.length == 4)
// Two host addresses // Two host addresses
constraintType = NAME_SAME_TYPE; constraintType = NAME_SAME_TYPE;
......
...@@ -261,6 +261,7 @@ public class IssuingDistributionPointExtension extends Extension ...@@ -261,6 +261,7 @@ public class IssuingDistributionPointExtension extends Extension
throw new IOException( throw new IOException(
"Attribute value should be of type ReasonFlags."); "Attribute value should be of type ReasonFlags.");
} }
revocationReasons = (ReasonFlags)obj;
} else if (name.equalsIgnoreCase(INDIRECT_CRL)) { } else if (name.equalsIgnoreCase(INDIRECT_CRL)) {
if (!(obj instanceof Boolean)) { if (!(obj instanceof Boolean)) {
...@@ -290,7 +291,6 @@ public class IssuingDistributionPointExtension extends Extension ...@@ -290,7 +291,6 @@ public class IssuingDistributionPointExtension extends Extension
} }
hasOnlyAttributeCerts = ((Boolean)obj).booleanValue(); hasOnlyAttributeCerts = ((Boolean)obj).booleanValue();
} else { } else {
throw new IOException("Attribute name [" + name + throw new IOException("Attribute name [" + name +
"] not recognized by " + "] not recognized by " +
......
...@@ -148,7 +148,7 @@ public class KeyIdentifier { ...@@ -148,7 +148,7 @@ public class KeyIdentifier {
return true; return true;
if (!(other instanceof KeyIdentifier)) if (!(other instanceof KeyIdentifier))
return false; return false;
return java.util.Arrays.equals(octetString, byte[] otherString = ((KeyIdentifier)other).octetString;
((KeyIdentifier)other).getIdentifier()); return java.util.Arrays.equals(octetString, otherString);
} }
} }
...@@ -102,7 +102,7 @@ implements CertAttrSet<String> { ...@@ -102,7 +102,7 @@ implements CertAttrSet<String> {
public PolicyMappingsExtension() { public PolicyMappingsExtension() {
extensionId = PKIXExtensions.KeyUsage_Id; extensionId = PKIXExtensions.KeyUsage_Id;
critical = false; critical = false;
maps = new ArrayList<CertificatePolicyMap>(); maps = Collections.<CertificatePolicyMap>emptyList();
} }
/** /**
......
...@@ -33,6 +33,7 @@ import java.security.cert.CertificateExpiredException; ...@@ -33,6 +33,7 @@ import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException; import java.security.cert.CertificateNotYetValidException;
import java.util.Date; import java.util.Date;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Objects;
import sun.security.util.*; import sun.security.util.*;
...@@ -206,16 +207,17 @@ implements CertAttrSet<String> { ...@@ -206,16 +207,17 @@ implements CertAttrSet<String> {
*/ */
public void valid(Date now) public void valid(Date now)
throws CertificateNotYetValidException, CertificateExpiredException { throws CertificateNotYetValidException, CertificateExpiredException {
Objects.requireNonNull(now);
/* /*
* we use the internal Dates rather than the passed in Date * we use the internal Dates rather than the passed in Date
* because someone could override the Date methods after() * because someone could override the Date methods after()
* and before() to do something entirely different. * and before() to do something entirely different.
*/ */
if (notBefore.after(now)) { if (notBefore != null && notBefore.after(now)) {
throw new CertificateNotYetValidException("NotBefore: " + throw new CertificateNotYetValidException("NotBefore: " +
notBefore.toString()); notBefore.toString());
} }
if (notAfter.before(now)) { if (notAfter != null && notAfter.before(now)) {
throw new CertificateExpiredException("NotAfter: " + throw new CertificateExpiredException("NotAfter: " +
notAfter.toString()); notAfter.toString());
} }
......
...@@ -27,6 +27,8 @@ package sun.security.x509; ...@@ -27,6 +27,8 @@ package sun.security.x509;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.util.Arrays;
import java.util.StringJoiner;
import java.util.*; import java.util.*;
import sun.security.util.*; import sun.security.util.*;
...@@ -442,31 +444,19 @@ public class RDN { ...@@ -442,31 +444,19 @@ public class RDN {
assertion[0].toRFC2253String(oidMap); assertion[0].toRFC2253String(oidMap);
} }
StringBuilder relname = new StringBuilder(); AVA[] toOutput = assertion;
if (!canonical) { if (canonical) {
for (int i = 0; i < assertion.length; i++) {
if (i > 0) {
relname.append('+');
}
relname.append(assertion[i].toRFC2253String(oidMap));
}
} else {
// order the string type AVA's alphabetically, // order the string type AVA's alphabetically,
// followed by the oid type AVA's numerically // followed by the oid type AVA's numerically
List<AVA> avaList = new ArrayList<AVA>(assertion.length); toOutput = assertion.clone();
for (int i = 0; i < assertion.length; i++) { Arrays.sort(toOutput, AVAComparator.getInstance());
avaList.add(assertion[i]); }
} StringJoiner sj = new StringJoiner("+");
java.util.Collections.sort(avaList, AVAComparator.getInstance()); for (AVA ava : toOutput) {
sj.add(canonical ? ava.toRFC2253CanonicalString()
for (int i = 0; i < avaList.size(); i++) { : ava.toRFC2253String(oidMap));
if (i > 0) {
relname.append('+');
}
relname.append(avaList.get(i).toRFC2253CanonicalString());
}
} }
return relname.toString(); return sj.toString();
} }
} }
......
...@@ -28,6 +28,7 @@ package sun.security.x509; ...@@ -28,6 +28,7 @@ package sun.security.x509;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Collections;
import java.util.*; import java.util.*;
import sun.security.util.DerOutputStream; import sun.security.util.DerOutputStream;
...@@ -200,7 +201,8 @@ public class SubjectInfoAccessExtension extends Extension ...@@ -200,7 +201,8 @@ public class SubjectInfoAccessExtension extends Extension
*/ */
public void delete(String name) throws IOException { public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(DESCRIPTIONS)) { if (name.equalsIgnoreCase(DESCRIPTIONS)) {
accessDescriptions = new ArrayList<AccessDescription>(); accessDescriptions =
Collections.<AccessDescription>emptyList();
} else { } else {
throw new IOException("Attribute name [" + name + throw new IOException("Attribute name [" + name +
"] not recognized by " + "] not recognized by " +
......
...@@ -165,7 +165,7 @@ public class URIName implements GeneralNameInterface { ...@@ -165,7 +165,7 @@ public class URIName implements GeneralNameInterface {
String host = uri.getSchemeSpecificPart(); String host = uri.getSchemeSpecificPart();
try { try {
DNSName hostDNS; DNSName hostDNS;
if (host.charAt(0) == '.') { if (host.startsWith(".")) {
hostDNS = new DNSName(host.substring(1)); hostDNS = new DNSName(host.substring(1));
} else { } else {
hostDNS = new DNSName(host); hostDNS = new DNSName(host);
......
...@@ -346,6 +346,8 @@ public class X500Name implements GeneralNameInterface, Principal { ...@@ -346,6 +346,8 @@ public class X500Name implements GeneralNameInterface, Principal {
for (int i = 0; i < names.length; i++) { for (int i = 0; i < names.length; i++) {
list.addAll(names[i].avas()); list.addAll(names[i].avas());
} }
list = Collections.unmodifiableList(list);
allAvaList = list;
} }
return list; return list;
} }
...@@ -364,9 +366,6 @@ public class X500Name implements GeneralNameInterface, Principal { ...@@ -364,9 +366,6 @@ public class X500Name implements GeneralNameInterface, Principal {
*/ */
public boolean isEmpty() { public boolean isEmpty() {
int n = names.length; int n = names.length;
if (n == 0) {
return true;
}
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
if (names[i].assertion.length != 0) { if (names[i].assertion.length != 0) {
return false; return false;
...@@ -1109,12 +1108,8 @@ public class X500Name implements GeneralNameInterface, Principal { ...@@ -1109,12 +1108,8 @@ public class X500Name implements GeneralNameInterface, Principal {
* and speed recognition of common X.500 attributes. * and speed recognition of common X.500 attributes.
*/ */
static ObjectIdentifier intern(ObjectIdentifier oid) { static ObjectIdentifier intern(ObjectIdentifier oid) {
ObjectIdentifier interned = internedOIDs.get(oid); ObjectIdentifier interned = internedOIDs.putIfAbsent(oid, oid);
if (interned != null) { return (interned == null) ? oid : interned;
return interned;
}
internedOIDs.put(oid, oid);
return oid;
} }
private static final Map<ObjectIdentifier,ObjectIdentifier> internedOIDs private static final Map<ObjectIdentifier,ObjectIdentifier> internedOIDs
......
...@@ -47,7 +47,7 @@ public class X509AttributeName { ...@@ -47,7 +47,7 @@ public class X509AttributeName {
*/ */
public X509AttributeName(String name) { public X509AttributeName(String name) {
int i = name.indexOf(SEPARATOR); int i = name.indexOf(SEPARATOR);
if (i == (-1)) { if (i < 0) {
prefix = name; prefix = name;
} else { } else {
prefix = name.substring(0, i); prefix = name.substring(0, i);
......
...@@ -742,9 +742,7 @@ public class X509CRLImpl extends X509CRL implements DerEncoder { ...@@ -742,9 +742,7 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
public byte[] getTBSCertList() throws CRLException { public byte[] getTBSCertList() throws CRLException {
if (tbsCertList == null) if (tbsCertList == null)
throw new CRLException("Uninitialized CRL"); throw new CRLException("Uninitialized CRL");
byte[] dup = new byte[tbsCertList.length]; return tbsCertList.clone();
System.arraycopy(tbsCertList, 0, dup, 0, dup.length);
return dup;
} }
/** /**
...@@ -755,9 +753,7 @@ public class X509CRLImpl extends X509CRL implements DerEncoder { ...@@ -755,9 +753,7 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
public byte[] getSignature() { public byte[] getSignature() {
if (signature == null) if (signature == null)
return null; return null;
byte[] dup = new byte[signature.length]; return signature.clone();
System.arraycopy(signature, 0, dup, 0, dup.length);
return dup;
} }
/** /**
......
...@@ -1008,9 +1008,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder { ...@@ -1008,9 +1008,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
public byte[] getSignature() { public byte[] getSignature() {
if (signature == null) if (signature == null)
return null; return null;
byte[] dup = new byte[signature.length]; return signature.clone();
System.arraycopy(signature, 0, dup, 0, dup.length);
return dup;
} }
/** /**
......
...@@ -180,6 +180,7 @@ struct sun_jpeg_source_mgr { ...@@ -180,6 +180,7 @@ struct sun_jpeg_source_mgr {
int *ip; int *ip;
unsigned char *bp; unsigned char *bp;
} outbuf; } outbuf;
size_t outbufSize;
jobject hOutputBuffer; jobject hOutputBuffer;
}; };
...@@ -235,6 +236,7 @@ static int GET_ARRAYS(JNIEnv *env, sun_jpeg_source_ptr src) ...@@ -235,6 +236,7 @@ static int GET_ARRAYS(JNIEnv *env, sun_jpeg_source_ptr src)
assert(src->outbuf.ip == 0); assert(src->outbuf.ip == 0);
src->outbuf.ip = (int *)(*env)->GetPrimitiveArrayCritical src->outbuf.ip = (int *)(*env)->GetPrimitiveArrayCritical
(env, src->hOutputBuffer, 0); (env, src->hOutputBuffer, 0);
src->outbufSize = (*env)->GetArrayLength(env, src->hOutputBuffer);
if (src->outbuf.ip == 0) { if (src->outbuf.ip == 0) {
RELEASE_ARRAYS(env, src); RELEASE_ARRAYS(env, src);
return 0; return 0;
...@@ -677,8 +679,8 @@ Java_sun_awt_image_JPEGImageDecoder_readImage(JNIEnv *env, ...@@ -677,8 +679,8 @@ Java_sun_awt_image_JPEGImageDecoder_readImage(JNIEnv *env,
cinfo.output_scanline - 1); cinfo.output_scanline - 1);
} else { } else {
if (hasalpha) { if (hasalpha) {
ip = jsrc.outbuf.ip + cinfo.image_width; ip = jsrc.outbuf.ip + jsrc.outbufSize;
bp = jsrc.outbuf.bp + cinfo.image_width * 4; bp = jsrc.outbuf.bp + jsrc.outbufSize * 4;
while (ip > jsrc.outbuf.ip) { while (ip > jsrc.outbuf.ip) {
pixel = (*--bp) << 24; pixel = (*--bp) << 24;
pixel |= (*--bp); pixel |= (*--bp);
...@@ -687,8 +689,8 @@ Java_sun_awt_image_JPEGImageDecoder_readImage(JNIEnv *env, ...@@ -687,8 +689,8 @@ Java_sun_awt_image_JPEGImageDecoder_readImage(JNIEnv *env,
*--ip = pixel; *--ip = pixel;
} }
} else { } else {
ip = jsrc.outbuf.ip + cinfo.image_width; ip = jsrc.outbuf.ip + jsrc.outbufSize;
bp = jsrc.outbuf.bp + cinfo.image_width * 3; bp = jsrc.outbuf.bp + jsrc.outbufSize * 3;
while (ip > jsrc.outbuf.ip) { while (ip > jsrc.outbuf.ip) {
pixel = (*--bp); pixel = (*--bp);
pixel |= (*--bp) << 8; pixel |= (*--bp) << 8;
......
...@@ -243,14 +243,14 @@ le_uint32 ContextualSubstitutionFormat1Subtable::process(const LETableReference ...@@ -243,14 +243,14 @@ le_uint32 ContextualSubstitutionFormat1Subtable::process(const LETableReference
le_uint16 srSetCount = SWAPW(subRuleSetCount); le_uint16 srSetCount = SWAPW(subRuleSetCount);
if (coverageIndex < srSetCount) { if (coverageIndex < srSetCount) {
LEReferenceToArrayOf<Offset> subRuleSetTableOffsetArrayRef(base, success, LEReferenceToArrayOf<Offset>
&subRuleSetTableOffsetArray[coverageIndex], 1); subRuleSetTableOffsetArrayRef(base, success, subRuleSetTableOffsetArray, srSetCount);
if (LE_FAILURE(success)) { if (LE_FAILURE(success)) {
return 0; return 0;
} }
Offset subRuleSetTableOffset = SWAPW(subRuleSetTableOffsetArray[coverageIndex]); Offset subRuleSetTableOffset = SWAPW(subRuleSetTableOffsetArray[coverageIndex]);
LEReferenceTo<SubRuleSetTable> LEReferenceTo<SubRuleSetTable> subRuleSetTable(base, success, subRuleSetTableOffset);
subRuleSetTable(base, success, (const SubRuleSetTable *) ((char *) this + subRuleSetTableOffset)); if (LE_FAILURE(success)) { return 0; }
le_uint16 subRuleCount = SWAPW(subRuleSetTable->subRuleCount); le_uint16 subRuleCount = SWAPW(subRuleSetTable->subRuleCount);
le_int32 position = glyphIterator->getCurrStreamPosition(); le_int32 position = glyphIterator->getCurrStreamPosition();
...@@ -264,6 +264,7 @@ le_uint32 ContextualSubstitutionFormat1Subtable::process(const LETableReference ...@@ -264,6 +264,7 @@ le_uint32 ContextualSubstitutionFormat1Subtable::process(const LETableReference
SWAPW(subRuleSetTable->subRuleTableOffsetArray[subRule]); SWAPW(subRuleSetTable->subRuleTableOffsetArray[subRule]);
LEReferenceTo<SubRuleTable> LEReferenceTo<SubRuleTable>
subRuleTable(subRuleSetTable, success, subRuleTableOffset); subRuleTable(subRuleSetTable, success, subRuleTableOffset);
if (LE_FAILURE(success)) { return 0; }
le_uint16 matchCount = SWAPW(subRuleTable->glyphCount) - 1; le_uint16 matchCount = SWAPW(subRuleTable->glyphCount) - 1;
le_uint16 substCount = SWAPW(subRuleTable->substCount); le_uint16 substCount = SWAPW(subRuleTable->substCount);
LEReferenceToArrayOf<TTGlyphID> inputGlyphArray(base, success, subRuleTable->inputGlyphArray, matchCount+2); LEReferenceToArrayOf<TTGlyphID> inputGlyphArray(base, success, subRuleTable->inputGlyphArray, matchCount+2);
...@@ -304,8 +305,8 @@ le_uint32 ContextualSubstitutionFormat2Subtable::process(const LETableReference ...@@ -304,8 +305,8 @@ le_uint32 ContextualSubstitutionFormat2Subtable::process(const LETableReference
} }
if (coverageIndex >= 0) { if (coverageIndex >= 0) {
LEReferenceTo<ClassDefinitionTable> classDefinitionTable(base, success, LEReferenceTo<ClassDefinitionTable> classDefinitionTable(base, success, SWAPW(classDefTableOffset));
(const ClassDefinitionTable *) ((char *) this + SWAPW(classDefTableOffset))); if (LE_FAILURE(success)) { return 0; }
le_uint16 scSetCount = SWAPW(subClassSetCount); le_uint16 scSetCount = SWAPW(subClassSetCount);
le_int32 setClass = classDefinitionTable->getGlyphClass(classDefinitionTable, le_int32 setClass = classDefinitionTable->getGlyphClass(classDefinitionTable,
glyphIterator->getCurrGlyphID(), glyphIterator->getCurrGlyphID(),
...@@ -313,44 +314,45 @@ le_uint32 ContextualSubstitutionFormat2Subtable::process(const LETableReference ...@@ -313,44 +314,45 @@ le_uint32 ContextualSubstitutionFormat2Subtable::process(const LETableReference
if (setClass < scSetCount) { if (setClass < scSetCount) {
LEReferenceToArrayOf<Offset> LEReferenceToArrayOf<Offset>
subClassSetTableOffsetArrayRef(base, success, subClassSetTableOffsetArray, setClass); subClassSetTableOffsetArrayRef(base, success, subClassSetTableOffsetArray, scSetCount);
if (LE_FAILURE(success)) { return 0; } if (LE_FAILURE(success)) { return 0; }
if (subClassSetTableOffsetArray[setClass] != 0) { if (subClassSetTableOffsetArray[setClass] != 0) {
Offset subClassSetTableOffset = SWAPW(subClassSetTableOffsetArray[setClass]); Offset subClassSetTableOffset = SWAPW(subClassSetTableOffsetArray[setClass]);
LEReferenceTo<SubClassSetTable> LEReferenceTo<SubClassSetTable> subClassSetTable(base, success, subClassSetTableOffset);
subClassSetTable(base, success, (const SubClassSetTable *) ((char *) this + subClassSetTableOffset)); if (LE_FAILURE(success)) { return 0; }
le_uint16 subClassRuleCount = SWAPW(subClassSetTable->subClassRuleCount); le_uint16 subClassRuleCount = SWAPW(subClassSetTable->subClassRuleCount);
le_int32 position = glyphIterator->getCurrStreamPosition(); le_int32 position = glyphIterator->getCurrStreamPosition();
LEReferenceToArrayOf<Offset> LEReferenceToArrayOf<Offset>
subClassRuleTableOffsetArrayRef(base, success, subClassSetTable->subClassRuleTableOffsetArray, subClassRuleCount); subClassRuleTableOffsetArrayRef(base, success, subClassSetTable->subClassRuleTableOffsetArray, subClassRuleCount);
if (LE_FAILURE(success)) { if (LE_FAILURE(success)) {
return 0; return 0;
} }
for (le_uint16 scRule = 0; scRule < subClassRuleCount; scRule += 1) { for (le_uint16 scRule = 0; scRule < subClassRuleCount; scRule += 1) {
Offset subClassRuleTableOffset = Offset subClassRuleTableOffset =
SWAPW(subClassSetTable->subClassRuleTableOffsetArray[scRule]); SWAPW(subClassSetTable->subClassRuleTableOffsetArray[scRule]);
LEReferenceTo<SubClassRuleTable> LEReferenceTo<SubClassRuleTable>
subClassRuleTable(subClassSetTable, success, subClassRuleTableOffset); subClassRuleTable(subClassSetTable, success, subClassRuleTableOffset);
le_uint16 matchCount = SWAPW(subClassRuleTable->glyphCount) - 1; if (LE_FAILURE(success)) { return 0; }
le_uint16 substCount = SWAPW(subClassRuleTable->substCount); le_uint16 matchCount = SWAPW(subClassRuleTable->glyphCount) - 1;
le_uint16 substCount = SWAPW(subClassRuleTable->substCount);
LEReferenceToArrayOf<le_uint16> classArray(base, success, subClassRuleTable->classArray, matchCount+1); LEReferenceToArrayOf<le_uint16> classArray(base, success, subClassRuleTable->classArray, matchCount+1);
if (LE_FAILURE(success)) { return 0; } if (LE_FAILURE(success)) { return 0; }
if (matchGlyphClasses(classArray, matchCount, glyphIterator, classDefinitionTable, success)) { if (matchGlyphClasses(classArray, matchCount, glyphIterator, classDefinitionTable, success)) {
LEReferenceToArrayOf<SubstitutionLookupRecord> LEReferenceToArrayOf<SubstitutionLookupRecord>
substLookupRecordArray(base, success, (const SubstitutionLookupRecord *) &subClassRuleTable->classArray[matchCount], substCount); substLookupRecordArray(base, success, (const SubstitutionLookupRecord *) &subClassRuleTable->classArray[matchCount], substCount);
applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success); applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
return matchCount + 1; return matchCount + 1;
} }
glyphIterator->setCurrStreamPosition(position); glyphIterator->setCurrStreamPosition(position);
}
} }
} }
}
// XXX If we get here, the table is mal-formed... // XXX If we get here, the table is mal-formed...
} }
...@@ -463,13 +465,13 @@ le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LETableRe ...@@ -463,13 +465,13 @@ le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LETableRe
if (coverageIndex < srSetCount) { if (coverageIndex < srSetCount) {
LEReferenceToArrayOf<Offset> LEReferenceToArrayOf<Offset>
chainSubRuleSetTableOffsetArrayRef(base, success, chainSubRuleSetTableOffsetArray, coverageIndex); chainSubRuleSetTableOffsetArrayRef(base, success, chainSubRuleSetTableOffsetArray, srSetCount);
if (LE_FAILURE(success)) { if (LE_FAILURE(success)) {
return 0; return 0;
} }
Offset chainSubRuleSetTableOffset = SWAPW(chainSubRuleSetTableOffsetArray[coverageIndex]); Offset chainSubRuleSetTableOffset = SWAPW(chainSubRuleSetTableOffsetArray[coverageIndex]);
LEReferenceTo<ChainSubRuleSetTable> LEReferenceTo<ChainSubRuleSetTable> chainSubRuleSetTable(base, success, chainSubRuleSetTableOffset);
chainSubRuleSetTable(base, success, (const ChainSubRuleSetTable *) ((char *) this + chainSubRuleSetTableOffset)); if (LE_FAILURE(success)) { return 0; }
le_uint16 chainSubRuleCount = SWAPW(chainSubRuleSetTable->chainSubRuleCount); le_uint16 chainSubRuleCount = SWAPW(chainSubRuleSetTable->chainSubRuleCount);
le_int32 position = glyphIterator->getCurrStreamPosition(); le_int32 position = glyphIterator->getCurrStreamPosition();
GlyphIterator tempIterator(*glyphIterator, emptyFeatureList); GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
...@@ -550,17 +552,17 @@ le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LETableRe ...@@ -550,17 +552,17 @@ le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LETableRe
if (coverageIndex >= 0) { if (coverageIndex >= 0) {
LEReferenceTo<ClassDefinitionTable> LEReferenceTo<ClassDefinitionTable>
backtrackClassDefinitionTable(base, success, (const ClassDefinitionTable *) ((char *) this + SWAPW(backtrackClassDefTableOffset))); backtrackClassDefinitionTable(base, success, SWAPW(backtrackClassDefTableOffset));
LEReferenceTo<ClassDefinitionTable> LEReferenceTo<ClassDefinitionTable>
inputClassDefinitionTable(base, success, (const ClassDefinitionTable *) ((char *) this + SWAPW(inputClassDefTableOffset))); inputClassDefinitionTable(base, success, SWAPW(inputClassDefTableOffset));
LEReferenceTo<ClassDefinitionTable> LEReferenceTo<ClassDefinitionTable>
lookaheadClassDefinitionTable(base, success, (const ClassDefinitionTable *) ((char *) this + SWAPW(lookaheadClassDefTableOffset))); lookaheadClassDefinitionTable(base, success, SWAPW(lookaheadClassDefTableOffset));
le_uint16 scSetCount = SWAPW(chainSubClassSetCount); le_uint16 scSetCount = SWAPW(chainSubClassSetCount);
le_int32 setClass = inputClassDefinitionTable->getGlyphClass(inputClassDefinitionTable, le_int32 setClass = inputClassDefinitionTable->getGlyphClass(inputClassDefinitionTable,
glyphIterator->getCurrGlyphID(), glyphIterator->getCurrGlyphID(),
success); success);
LEReferenceToArrayOf<Offset> LEReferenceToArrayOf<Offset>
chainSubClassSetTableOffsetArrayRef(base, success, chainSubClassSetTableOffsetArray, setClass); chainSubClassSetTableOffsetArrayRef(base, success, chainSubClassSetTableOffsetArray, scSetCount);
if (LE_FAILURE(success)) { if (LE_FAILURE(success)) {
return 0; return 0;
} }
...@@ -568,7 +570,8 @@ le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LETableRe ...@@ -568,7 +570,8 @@ le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LETableRe
if (setClass < scSetCount && chainSubClassSetTableOffsetArray[setClass] != 0) { if (setClass < scSetCount && chainSubClassSetTableOffsetArray[setClass] != 0) {
Offset chainSubClassSetTableOffset = SWAPW(chainSubClassSetTableOffsetArray[setClass]); Offset chainSubClassSetTableOffset = SWAPW(chainSubClassSetTableOffsetArray[setClass]);
LEReferenceTo<ChainSubClassSetTable> LEReferenceTo<ChainSubClassSetTable>
chainSubClassSetTable(base, success, (const ChainSubClassSetTable *) ((char *) this + chainSubClassSetTableOffset)); chainSubClassSetTable(base, success, chainSubClassSetTableOffset);
if (LE_FAILURE(success)) { return 0; }
le_uint16 chainSubClassRuleCount = SWAPW(chainSubClassSetTable->chainSubClassRuleCount); le_uint16 chainSubClassRuleCount = SWAPW(chainSubClassSetTable->chainSubClassRuleCount);
le_int32 position = glyphIterator->getCurrStreamPosition(); le_int32 position = glyphIterator->getCurrStreamPosition();
GlyphIterator tempIterator(*glyphIterator, emptyFeatureList); GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
...@@ -582,6 +585,7 @@ le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LETableRe ...@@ -582,6 +585,7 @@ le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LETableRe
SWAPW(chainSubClassSetTable->chainSubClassRuleTableOffsetArray[scRule]); SWAPW(chainSubClassSetTable->chainSubClassRuleTableOffsetArray[scRule]);
LEReferenceTo<ChainSubClassRuleTable> LEReferenceTo<ChainSubClassRuleTable>
chainSubClassRuleTable(chainSubClassSetTable, success, chainSubClassRuleTableOffset); chainSubClassRuleTable(chainSubClassSetTable, success, chainSubClassRuleTableOffset);
if (LE_FAILURE(success)) { return 0; }
le_uint16 backtrackGlyphCount = SWAPW(chainSubClassRuleTable->backtrackGlyphCount); le_uint16 backtrackGlyphCount = SWAPW(chainSubClassRuleTable->backtrackGlyphCount);
LEReferenceToArrayOf<le_uint16> backtrackClassArray(base, success, chainSubClassRuleTable->backtrackClassArray, backtrackGlyphCount); LEReferenceToArrayOf<le_uint16> backtrackClassArray(base, success, chainSubClassRuleTable->backtrackClassArray, backtrackGlyphCount);
if( LE_FAILURE(success) ) { return 0; } if( LE_FAILURE(success) ) { return 0; }
......
...@@ -46,7 +46,7 @@ le_uint32 CursiveAttachmentSubtable::process(const LEReferenceTo<CursiveAttachme ...@@ -46,7 +46,7 @@ le_uint32 CursiveAttachmentSubtable::process(const LEReferenceTo<CursiveAttachme
le_uint16 eeCount = SWAPW(entryExitCount); le_uint16 eeCount = SWAPW(entryExitCount);
LEReferenceToArrayOf<EntryExitRecord> LEReferenceToArrayOf<EntryExitRecord>
entryExitRecordsArrayRef(base, success, entryExitRecords, coverageIndex); entryExitRecordsArrayRef(base, success, entryExitRecords, eeCount);
if (coverageIndex < 0 || coverageIndex >= eeCount || LE_FAILURE(success)) { if (coverageIndex < 0 || coverageIndex >= eeCount || LE_FAILURE(success)) {
glyphIterator->setCursiveGlyph(); glyphIterator->setCursiveGlyph();
......
...@@ -41,7 +41,7 @@ U_NAMESPACE_BEGIN ...@@ -41,7 +41,7 @@ U_NAMESPACE_BEGIN
LEReferenceTo<FeatureTable> FeatureListTable::getFeatureTable(const LETableReference &base, le_uint16 featureIndex, LETag *featureTag, LEErrorCode &success) const LEReferenceTo<FeatureTable> FeatureListTable::getFeatureTable(const LETableReference &base, le_uint16 featureIndex, LETag *featureTag, LEErrorCode &success) const
{ {
LEReferenceToArrayOf<FeatureRecord> LEReferenceToArrayOf<FeatureRecord>
featureRecordArrayRef(base, success, featureRecordArray, featureIndex+1); featureRecordArrayRef(base, success, featureRecordArray, SWAPW(featureCount));
if (featureIndex >= SWAPW(featureCount) || LE_FAILURE(success)) { if (featureIndex >= SWAPW(featureCount) || LE_FAILURE(success)) {
return LEReferenceTo<FeatureTable>(); return LEReferenceTo<FeatureTable>();
......
...@@ -93,7 +93,7 @@ le_int32 MarkToBasePositioningSubtable::process(const LETableReference &base, Gl ...@@ -93,7 +93,7 @@ le_int32 MarkToBasePositioningSubtable::process(const LETableReference &base, Gl
} }
LEReferenceTo<BaseRecord> baseRecord(base, success, &baseArray->baseRecordArray[baseCoverage * mcCount]); LEReferenceTo<BaseRecord> baseRecord(base, success, &baseArray->baseRecordArray[baseCoverage * mcCount]);
if( LE_FAILURE(success) ) { return 0; } if( LE_FAILURE(success) ) { return 0; }
LEReferenceToArrayOf<Offset> baseAnchorTableOffsetArray(base, success, &(baseRecord->baseAnchorTableOffsetArray[0]), markClass+1); LEReferenceToArrayOf<Offset> baseAnchorTableOffsetArray(base, success, &(baseRecord->baseAnchorTableOffsetArray[0]), mcCount);
if( LE_FAILURE(success) ) { return 0; } if( LE_FAILURE(success) ) { return 0; }
Offset anchorTableOffset = SWAPW(baseRecord->baseAnchorTableOffsetArray[markClass]); Offset anchorTableOffset = SWAPW(baseRecord->baseAnchorTableOffsetArray[markClass]);
......
...@@ -83,6 +83,7 @@ le_int32 MarkToLigaturePositioningSubtable::process(const LETableReference &base ...@@ -83,6 +83,7 @@ le_int32 MarkToLigaturePositioningSubtable::process(const LETableReference &base
LEGlyphID ligatureGlyph = findLigatureGlyph(&ligatureIterator); LEGlyphID ligatureGlyph = findLigatureGlyph(&ligatureIterator);
le_int32 ligatureCoverage = getBaseCoverage(base, (LEGlyphID) ligatureGlyph, success); le_int32 ligatureCoverage = getBaseCoverage(base, (LEGlyphID) ligatureGlyph, success);
LEReferenceTo<LigatureArray> ligatureArray(base, success, SWAPW(baseArrayOffset)); LEReferenceTo<LigatureArray> ligatureArray(base, success, SWAPW(baseArrayOffset));
if (LE_FAILURE(success)) { return 0; }
le_uint16 ligatureCount = SWAPW(ligatureArray->ligatureCount); le_uint16 ligatureCount = SWAPW(ligatureArray->ligatureCount);
if (ligatureCoverage < 0 || ligatureCoverage >= ligatureCount) { if (ligatureCoverage < 0 || ligatureCoverage >= ligatureCount) {
...@@ -95,6 +96,7 @@ le_int32 MarkToLigaturePositioningSubtable::process(const LETableReference &base ...@@ -95,6 +96,7 @@ le_int32 MarkToLigaturePositioningSubtable::process(const LETableReference &base
le_int32 markPosition = glyphIterator->getCurrStreamPosition(); le_int32 markPosition = glyphIterator->getCurrStreamPosition();
Offset ligatureAttachOffset = SWAPW(ligatureArray->ligatureAttachTableOffsetArray[ligatureCoverage]); Offset ligatureAttachOffset = SWAPW(ligatureArray->ligatureAttachTableOffsetArray[ligatureCoverage]);
LEReferenceTo<LigatureAttachTable> ligatureAttachTable(ligatureArray, success, ligatureAttachOffset); LEReferenceTo<LigatureAttachTable> ligatureAttachTable(ligatureArray, success, ligatureAttachOffset);
if (LE_FAILURE(success)) { return 0; }
le_int32 componentCount = SWAPW(ligatureAttachTable->componentCount); le_int32 componentCount = SWAPW(ligatureAttachTable->componentCount);
le_int32 component = ligatureIterator.getMarkComponent(markPosition); le_int32 component = ligatureIterator.getMarkComponent(markPosition);
...@@ -104,10 +106,12 @@ le_int32 MarkToLigaturePositioningSubtable::process(const LETableReference &base ...@@ -104,10 +106,12 @@ le_int32 MarkToLigaturePositioningSubtable::process(const LETableReference &base
} }
LEReferenceTo<ComponentRecord> componentRecord(base, success, &ligatureAttachTable->componentRecordArray[component * mcCount]); LEReferenceTo<ComponentRecord> componentRecord(base, success, &ligatureAttachTable->componentRecordArray[component * mcCount]);
LEReferenceToArrayOf<Offset> ligatureAnchorTableOffsetArray(base, success, &(componentRecord->ligatureAnchorTableOffsetArray[0]), markClass+1); if (LE_FAILURE(success)) { return 0; }
LEReferenceToArrayOf<Offset> ligatureAnchorTableOffsetArray(base, success, &(componentRecord->ligatureAnchorTableOffsetArray[0]), mcCount);
if( LE_FAILURE(success) ) { return 0; } if( LE_FAILURE(success) ) { return 0; }
Offset anchorTableOffset = SWAPW(componentRecord->ligatureAnchorTableOffsetArray[markClass]); Offset anchorTableOffset = SWAPW(componentRecord->ligatureAnchorTableOffsetArray[markClass]);
LEReferenceTo<AnchorTable> anchorTable(ligatureAttachTable, success, anchorTableOffset); LEReferenceTo<AnchorTable> anchorTable(ligatureAttachTable, success, anchorTableOffset);
if (LE_FAILURE(success)) { return 0; }
LEPoint ligatureAnchor, markAdvance, pixels; LEPoint ligatureAnchor, markAdvance, pixels;
anchorTable->getAnchor(anchorTable, ligatureGlyph, fontInstance, ligatureAnchor, success); anchorTable->getAnchor(anchorTable, ligatureGlyph, fontInstance, ligatureAnchor, success);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册