提交 1c69e49b 编写于 作者: A asaha

Merge

...@@ -708,6 +708,9 @@ c92d704420d707d3016d8ee3a4239d1c57692ddd jdk8u141-b10 ...@@ -708,6 +708,9 @@ c92d704420d707d3016d8ee3a4239d1c57692ddd jdk8u141-b10
0000000000000000000000000000000000000000 jdk8u141-b12 0000000000000000000000000000000000000000 jdk8u141-b12
996632997de8c889067dafd5a5827146e02c9130 jdk8u141-b12 996632997de8c889067dafd5a5827146e02c9130 jdk8u141-b12
c6bc194fedb63b20c45c793405d215d206fb4654 jdk8u141-b13 c6bc194fedb63b20c45c793405d215d206fb4654 jdk8u141-b13
072e084bceeedeb75467e40ca77786ac9ef5227a jdk8u151-b00
5b0fa6e004312a5910a6a70e4fbc0f00a678e650 jdk8u151-b01
bd40efd56b4544ff9048d2f7be4cf108b281a6f3 jdk8u151-b02
1442bc728814af451e2dd1a6719a64485d27e3a0 jdk8u122-b00 1442bc728814af451e2dd1a6719a64485d27e3a0 jdk8u122-b00
f6030acfa5aec0e64d45adfac69b9e7e5c12bc74 jdk8u122-b01 f6030acfa5aec0e64d45adfac69b9e7e5c12bc74 jdk8u122-b01
6b072c3a6db7ab06804c91aab77431799dfb5d47 jdk8u122-b02 6b072c3a6db7ab06804c91aab77431799dfb5d47 jdk8u122-b02
......
/* /*
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2017, 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
...@@ -156,7 +156,7 @@ abstract class AESCipher extends CipherSpi { ...@@ -156,7 +156,7 @@ abstract class AESCipher extends CipherSpi {
throw new InvalidKeyException("Key encoding must not be null"); throw new InvalidKeyException("Key encoding must not be null");
} else if (value.length != fixedKeySize) { } else if (value.length != fixedKeySize) {
throw new InvalidKeyException("The key must be " + throw new InvalidKeyException("The key must be " +
fixedKeySize*8 + " bits"); fixedKeySize + " bytes");
} }
} }
} }
...@@ -509,7 +509,7 @@ abstract class AESCipher extends CipherSpi { ...@@ -509,7 +509,7 @@ abstract class AESCipher extends CipherSpi {
throw new InvalidKeyException("Invalid AES key length: " + throw new InvalidKeyException("Invalid AES key length: " +
encoded.length + " bytes"); encoded.length + " bytes");
} }
return encoded.length * 8; return Math.multiplyExact(encoded.length, 8);
} }
/** /**
...@@ -628,9 +628,9 @@ abstract class AESCipher extends CipherSpi { ...@@ -628,9 +628,9 @@ abstract class AESCipher extends CipherSpi {
} }
if (src != null) { if (src != null) {
int aadLen = src.limit() - src.position(); int aadLen = src.limit() - src.position();
if (aadLen != 0) { if (aadLen > 0) {
if (src.hasArray()) { if (src.hasArray()) {
int aadOfs = src.arrayOffset() + src.position(); int aadOfs = Math.addExact(src.arrayOffset(), src.position());
core.updateAAD(src.array(), aadOfs, aadLen); core.updateAAD(src.array(), aadOfs, aadLen);
src.position(src.limit()); src.position(src.limit());
} else { } else {
......
/* /*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2017, 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
...@@ -156,7 +156,7 @@ abstract class AESWrapCipher extends CipherSpi { ...@@ -156,7 +156,7 @@ abstract class AESWrapCipher extends CipherSpi {
if (decrypting) { if (decrypting) {
result = inputLen - 8; result = inputLen - 8;
} else { } else {
result = inputLen + 8; result = Math.addExact(inputLen, 8);
} }
return (result < 0? 0:result); return (result < 0? 0:result);
} }
...@@ -378,7 +378,7 @@ abstract class AESWrapCipher extends CipherSpi { ...@@ -378,7 +378,7 @@ abstract class AESWrapCipher extends CipherSpi {
throw new InvalidKeyException("Invalid key length: " + throw new InvalidKeyException("Invalid key length: " +
encoded.length + " bytes"); encoded.length + " bytes");
} }
return encoded.length * 8; return Math.multiplyExact(encoded.length, 8);
} }
/** /**
...@@ -404,7 +404,7 @@ abstract class AESWrapCipher extends CipherSpi { ...@@ -404,7 +404,7 @@ abstract class AESWrapCipher extends CipherSpi {
throw new InvalidKeyException("Cannot get an encoding of " + throw new InvalidKeyException("Cannot get an encoding of " +
"the key to be wrapped"); "the key to be wrapped");
} }
byte[] out = new byte[keyVal.length + 8]; byte[] out = new byte[Math.addExact(keyVal.length, 8)];
if (keyVal.length == 8) { if (keyVal.length == 8) {
System.arraycopy(IV, 0, out, 0, IV.length); System.arraycopy(IV, 0, out, 0, IV.length);
......
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2017, 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
...@@ -257,7 +257,7 @@ public final class ARCFOURCipher extends CipherSpi { ...@@ -257,7 +257,7 @@ public final class ARCFOURCipher extends CipherSpi {
// see JCE spec // see JCE spec
protected int engineGetKeySize(Key key) throws InvalidKeyException { protected int engineGetKeySize(Key key) throws InvalidKeyException {
byte[] encodedKey = getEncodedKey(key); byte[] encodedKey = getEncodedKey(key);
return encodedKey.length << 3; return Math.multiplyExact(encodedKey.length, 8);
} }
} }
/* /*
* Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2017, 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
...@@ -373,7 +373,7 @@ public final class BlowfishCipher extends CipherSpi { ...@@ -373,7 +373,7 @@ public final class BlowfishCipher extends CipherSpi {
* @exception InvalidKeyException if <code>key</code> is invalid. * @exception InvalidKeyException if <code>key</code> is invalid.
*/ */
protected int engineGetKeySize(Key key) throws InvalidKeyException { protected int engineGetKeySize(Key key) throws InvalidKeyException {
return (key.getEncoded().length * 8); return Math.multiplyExact(key.getEncoded().length, 8);
} }
/** /**
......
/* /*
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2017, 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
...@@ -324,13 +324,14 @@ final class CipherCore { ...@@ -324,13 +324,14 @@ final class CipherCore {
} }
private int getOutputSizeByOperation(int inputLen, boolean isDoFinal) { private int getOutputSizeByOperation(int inputLen, boolean isDoFinal) {
int totalLen = buffered + inputLen + cipher.getBufferedLength(); int totalLen = Math.addExact(buffered, cipher.getBufferedLength());
totalLen = Math.addExact(totalLen, inputLen);
switch (cipherMode) { switch (cipherMode) {
case GCM_MODE: case GCM_MODE:
if (isDoFinal) { if (isDoFinal) {
int tagLen = ((GaloisCounterMode) cipher).getTagLen(); int tagLen = ((GaloisCounterMode) cipher).getTagLen();
if (!decrypting) { if (!decrypting) {
totalLen += tagLen; totalLen = Math.addExact(totalLen, tagLen);
} else { } else {
totalLen -= tagLen; totalLen -= tagLen;
} }
...@@ -346,10 +347,10 @@ final class CipherCore { ...@@ -346,10 +347,10 @@ final class CipherCore {
totalLen = diffBlocksize; totalLen = diffBlocksize;
} else { } else {
int residue = (totalLen - diffBlocksize) % blockSize; int residue = (totalLen - diffBlocksize) % blockSize;
totalLen += (blockSize - residue); totalLen = Math.addExact(totalLen, (blockSize - residue));
} }
} else { } else {
totalLen += padding.padLength(totalLen); totalLen = Math.addExact(totalLen, padding.padLength(totalLen));
} }
} }
break; break;
...@@ -711,7 +712,8 @@ final class CipherCore { ...@@ -711,7 +712,8 @@ final class CipherCore {
} }
// figure out how much can be sent to crypto function // figure out how much can be sent to crypto function
int len = buffered + inputLen - minBytes; int len = Math.addExact(buffered, inputLen);
len -= minBytes;
if (padding != null && decrypting) { if (padding != null && decrypting) {
// do not include the padding bytes when decrypting // do not include the padding bytes when decrypting
len -= blockSize; len -= blockSize;
...@@ -730,12 +732,12 @@ final class CipherCore { ...@@ -730,12 +732,12 @@ final class CipherCore {
int outLen = 0; int outLen = 0;
if (len != 0) { // there is some work to do if (len != 0) { // there is some work to do
if ((input == output) if ((input == output)
&& (outputOffset < (inputOffset + inputLen)) && (outputOffset - inputOffset < inputLen)
&& (inputOffset < (outputOffset + buffer.length))) { && (inputOffset - outputOffset < buffer.length)) {
// copy 'input' out to avoid its content being // copy 'input' out to avoid its content being
// overwritten prematurely. // overwritten prematurely.
input = Arrays.copyOfRange(input, inputOffset, input = Arrays.copyOfRange(input, inputOffset,
inputOffset + inputLen); Math.addExact(inputOffset, inputLen));
inputOffset = 0; inputOffset = 0;
} }
if (len <= buffered) { if (len <= buffered) {
...@@ -757,13 +759,13 @@ final class CipherCore { ...@@ -757,13 +759,13 @@ final class CipherCore {
if (bufferCapacity != 0) { if (bufferCapacity != 0) {
temp = Math.min(bufferCapacity, inputConsumed); temp = Math.min(bufferCapacity, inputConsumed);
if (unitBytes != blockSize) { if (unitBytes != blockSize) {
temp -= ((buffered + temp) % unitBytes); temp -= (Math.addExact(buffered, temp) % unitBytes);
} }
System.arraycopy(input, inputOffset, buffer, buffered, temp); System.arraycopy(input, inputOffset, buffer, buffered, temp);
inputOffset += temp; inputOffset = Math.addExact(inputOffset, temp);
inputConsumed -= temp; inputConsumed -= temp;
inputLen -= temp; inputLen -= temp;
buffered += temp; buffered = Math.addExact(buffered, temp);
} }
// process 'buffer' // process 'buffer'
if (decrypting) { if (decrypting) {
...@@ -771,7 +773,7 @@ final class CipherCore { ...@@ -771,7 +773,7 @@ final class CipherCore {
} else { } else {
outLen = cipher.encrypt(buffer, 0, buffered, output, outputOffset); outLen = cipher.encrypt(buffer, 0, buffered, output, outputOffset);
} }
outputOffset += outLen; outputOffset = Math.addExact(outputOffset, outLen);
buffered = 0; buffered = 0;
} }
if (inputConsumed > 0) { // still has input to process if (inputConsumed > 0) { // still has input to process
...@@ -802,7 +804,7 @@ final class CipherCore { ...@@ -802,7 +804,7 @@ final class CipherCore {
if (inputLen > 0) { if (inputLen > 0) {
System.arraycopy(input, inputOffset, buffer, buffered, System.arraycopy(input, inputOffset, buffer, buffered,
inputLen); inputLen);
buffered += inputLen; buffered = Math.addExact(buffered, inputLen);
} }
return outLen; return outLen;
} }
...@@ -912,10 +914,10 @@ final class CipherCore { ...@@ -912,10 +914,10 @@ final class CipherCore {
} }
// calculate total input length // calculate total input length
int len = buffered + inputLen; int len = Math.addExact(buffered, inputLen);
// calculate padding length // calculate padding length
int totalLen = len + cipher.getBufferedLength(); int totalLen = Math.addExact(len, cipher.getBufferedLength());
int paddingLen = 0; int paddingLen = 0;
// will the total input length be a multiple of blockSize? // will the total input length be a multiple of blockSize?
if (unitBytes != blockSize) { if (unitBytes != blockSize) {
...@@ -948,12 +950,12 @@ final class CipherCore { ...@@ -948,12 +950,12 @@ final class CipherCore {
int finalBufLen = inputLen; int finalBufLen = inputLen;
if ((buffered != 0) || (!decrypting && padding != null) || if ((buffered != 0) || (!decrypting && padding != null) ||
((input == output) ((input == output)
&& (outputOffset < (inputOffset + inputLen)) && (outputOffset - inputOffset < inputLen)
&& (inputOffset < (outputOffset + buffer.length)))) { && (inputOffset - outputOffset < buffer.length))) {
if (decrypting || padding == null) { if (decrypting || padding == null) {
paddingLen = 0; paddingLen = 0;
} }
finalBuf = new byte[len + paddingLen]; finalBuf = new byte[Math.addExact(len, paddingLen)];
finalOffset = 0; finalOffset = 0;
if (buffered != 0) { if (buffered != 0) {
System.arraycopy(buffer, 0, finalBuf, 0, buffered); System.arraycopy(buffer, 0, finalBuf, 0, buffered);
...@@ -963,7 +965,7 @@ final class CipherCore { ...@@ -963,7 +965,7 @@ final class CipherCore {
buffered, inputLen); buffered, inputLen);
} }
if (paddingLen != 0) { if (paddingLen != 0) {
padding.padWithLen(finalBuf, (buffered+inputLen), paddingLen); padding.padWithLen(finalBuf, Math.addExact(buffered, inputLen), paddingLen);
} }
finalBufLen = finalBuf.length; finalBufLen = finalBuf.length;
} }
......
/* /*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2017, 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
...@@ -140,7 +140,7 @@ public final class DESedeWrapCipher extends CipherSpi { ...@@ -140,7 +140,7 @@ public final class DESedeWrapCipher extends CipherSpi {
if (decrypting) { if (decrypting) {
result = inputLen - 16; // CHECKSUM_LEN + IV_LEN; result = inputLen - 16; // CHECKSUM_LEN + IV_LEN;
} else { } else {
result = inputLen + 16; result = Math.addExact(inputLen, 16);
} }
return (result < 0? 0:result); return (result < 0? 0:result);
} }
...@@ -452,11 +452,11 @@ public final class DESedeWrapCipher extends CipherSpi { ...@@ -452,11 +452,11 @@ public final class DESedeWrapCipher extends CipherSpi {
} }
byte[] cks = getChecksum(keyVal); byte[] cks = getChecksum(keyVal);
byte[] in = new byte[keyVal.length + CHECKSUM_LEN]; byte[] in = new byte[Math.addExact(keyVal.length, CHECKSUM_LEN)];
System.arraycopy(keyVal, 0, in, 0, keyVal.length); System.arraycopy(keyVal, 0, in, 0, keyVal.length);
System.arraycopy(cks, 0, in, keyVal.length, CHECKSUM_LEN); System.arraycopy(cks, 0, in, keyVal.length, CHECKSUM_LEN);
byte[] out = new byte[iv.length + in.length]; byte[] out = new byte[Math.addExact(iv.length, in.length)];
System.arraycopy(iv, 0, out, 0, iv.length); System.arraycopy(iv, 0, out, 0, iv.length);
cipher.encrypt(in, 0, in.length, out, iv.length); cipher.encrypt(in, 0, in.length, out, iv.length);
......
/* /*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2017, 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
...@@ -63,15 +63,16 @@ final class ISO10126Padding implements Padding { ...@@ -63,15 +63,16 @@ final class ISO10126Padding implements Padding {
if (in == null) if (in == null)
return; return;
if ((off + len) > in.length) { int idx = Math.addExact(off, len);
if (idx > in.length) {
throw new ShortBufferException("Buffer too small to hold padding"); throw new ShortBufferException("Buffer too small to hold padding");
} }
byte paddingOctet = (byte) (len & 0xff); byte paddingOctet = (byte) (len & 0xff);
byte[] padding = new byte[len]; byte[] padding = new byte[len - 1];
SunJCE.getRandom().nextBytes(padding); SunJCE.getRandom().nextBytes(padding);
padding[len-1] = paddingOctet; System.arraycopy(padding, 0, in, off, len - 1);
System.arraycopy(padding, 0, in, off, len); in[idx - 1] = paddingOctet;
return; return;
} }
...@@ -94,14 +95,15 @@ final class ISO10126Padding implements Padding { ...@@ -94,14 +95,15 @@ final class ISO10126Padding implements Padding {
return 0; return 0;
} }
byte lastByte = in[off + len - 1]; int idx = Math.addExact(off, len);
byte lastByte = in[idx - 1];
int padValue = (int)lastByte & 0x0ff; int padValue = (int)lastByte & 0x0ff;
if ((padValue < 0x01) if ((padValue < 0x01)
|| (padValue > blockSize)) { || (padValue > blockSize)) {
return -1; return -1;
} }
int start = off + len - ((int)lastByte & 0x0ff); int start = idx - padValue;
if (start < off) { if (start < off) {
return -1; return -1;
} }
......
/* /*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2017, 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
...@@ -260,7 +260,7 @@ final class PBES1Core { ...@@ -260,7 +260,7 @@ final class PBES1Core {
if (algo.equals("DES")) { if (algo.equals("DES")) {
// P || S (password concatenated with salt) // P || S (password concatenated with salt)
byte[] concat = new byte[passwdBytes.length + salt.length]; byte[] concat = new byte[Math.addExact(passwdBytes.length, salt.length)];
System.arraycopy(passwdBytes, 0, concat, 0, passwdBytes.length); System.arraycopy(passwdBytes, 0, concat, 0, passwdBytes.length);
java.util.Arrays.fill(passwdBytes, (byte)0x00); java.util.Arrays.fill(passwdBytes, (byte)0x00);
System.arraycopy(salt, 0, concat, passwdBytes.length, salt.length); System.arraycopy(salt, 0, concat, passwdBytes.length, salt.length);
......
/* /*
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2017, 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
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import javax.crypto.ShortBufferException; import javax.crypto.ShortBufferException;
import java.util.Arrays;
/** /**
* This class implements padding as specified in the PKCS#5 standard. * This class implements padding as specified in the PKCS#5 standard.
...@@ -63,14 +64,13 @@ final class PKCS5Padding implements Padding { ...@@ -63,14 +64,13 @@ final class PKCS5Padding implements Padding {
if (in == null) if (in == null)
return; return;
if ((off + len) > in.length) { int idx = Math.addExact(off, len);
if (idx > in.length) {
throw new ShortBufferException("Buffer too small to hold padding"); throw new ShortBufferException("Buffer too small to hold padding");
} }
byte paddingOctet = (byte) (len & 0xff); byte paddingOctet = (byte) (len & 0xff);
for (int i = 0; i < len; i++) { Arrays.fill(in, off, idx, paddingOctet);
in[i + off] = paddingOctet;
}
return; return;
} }
...@@ -92,25 +92,24 @@ final class PKCS5Padding implements Padding { ...@@ -92,25 +92,24 @@ final class PKCS5Padding implements Padding {
(len == 0)) { // this can happen if input is really a padded buffer (len == 0)) { // this can happen if input is really a padded buffer
return 0; return 0;
} }
int idx = Math.addExact(off, len);
byte lastByte = in[off + len - 1]; byte lastByte = in[idx - 1];
int padValue = (int)lastByte & 0x0ff; int padValue = (int)lastByte & 0x0ff;
if ((padValue < 0x01) if ((padValue < 0x01)
|| (padValue > blockSize)) { || (padValue > blockSize)) {
return -1; return -1;
} }
int start = off + len - ((int)lastByte & 0x0ff); int start = idx - padValue;
if (start < off) { if (start < off) {
return -1; return -1;
} }
for (int i = 0; i < ((int)lastByte & 0x0ff); i++) { for (int i = start; i < idx; i++) {
if (in[start+i] != lastByte) { if (in[i] != lastByte) {
return -1; return -1;
} }
} }
return start; return start;
} }
......
...@@ -38,6 +38,7 @@ package com.sun.net.ssl.internal.www.protocol.https; ...@@ -38,6 +38,7 @@ package com.sun.net.ssl.internal.www.protocol.https;
import java.net.URL; import java.net.URL;
import java.net.Proxy; import java.net.Proxy;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.net.MalformedURLException;
import java.io.*; import java.io.*;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.security.Permission; import java.security.Permission;
...@@ -75,10 +76,18 @@ public class HttpsURLConnectionOldImpl ...@@ -75,10 +76,18 @@ public class HttpsURLConnectionOldImpl
this(u, null, handler); this(u, null, handler);
} }
static URL checkURL(URL u) throws IOException {
if (u != null) {
if (u.toExternalForm().indexOf('\n') > -1) {
throw new MalformedURLException("Illegal character in URL");
}
}
return u;
}
// For both copies of the file, uncomment one line and comment the other // For both copies of the file, uncomment one line and comment the other
// HttpsURLConnectionImpl(URL u, Handler handler) throws IOException { // HttpsURLConnectionImpl(URL u, Handler handler) throws IOException {
HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException { HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException {
super(u); super(checkURL(u));
delegate = new DelegateHttpsURLConnection(url, p, handler, this); delegate = new DelegateHttpsURLConnection(url, p, handler, this);
} }
......
...@@ -825,18 +825,36 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -825,18 +825,36 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
this(u, null, handler); this(u, null, handler);
} }
public HttpURLConnection(URL u, String host, int port) { private static String checkHost(String h) throws IOException {
this(u, new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(host, port))); if (h != null) {
if (h.indexOf('\n') > -1) {
throw new MalformedURLException("Illegal character in host");
}
}
return h;
}
public HttpURLConnection(URL u, String host, int port) throws IOException {
this(u, new Proxy(Proxy.Type.HTTP,
InetSocketAddress.createUnresolved(checkHost(host), port)));
} }
/** this constructor is used by other protocol handlers such as ftp /** this constructor is used by other protocol handlers such as ftp
that want to use http to fetch urls on their behalf.*/ that want to use http to fetch urls on their behalf.*/
public HttpURLConnection(URL u, Proxy p) { public HttpURLConnection(URL u, Proxy p) throws IOException {
this(u, p, new Handler()); this(u, p, new Handler());
} }
protected HttpURLConnection(URL u, Proxy p, Handler handler) { private static URL checkURL(URL u) throws IOException {
super(u); if (u != null) {
if (u.toExternalForm().indexOf('\n') > -1) {
throw new MalformedURLException("Illegal character in URL");
}
}
return u;
}
protected HttpURLConnection(URL u, Proxy p, Handler handler)
throws IOException {
super(checkURL(u));
requests = new MessageHeader(); requests = new MessageHeader();
responses = new MessageHeader(); responses = new MessageHeader();
userHeaders = new MessageHeader(); userHeaders = new MessageHeader();
......
...@@ -38,6 +38,7 @@ package sun.net.www.protocol.https; ...@@ -38,6 +38,7 @@ package sun.net.www.protocol.https;
import java.net.URL; import java.net.URL;
import java.net.Proxy; import java.net.Proxy;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.net.MalformedURLException;
import java.io.*; import java.io.*;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.security.Permission; import java.security.Permission;
...@@ -79,10 +80,18 @@ public class HttpsURLConnectionImpl ...@@ -79,10 +80,18 @@ public class HttpsURLConnectionImpl
this(u, null, handler); this(u, null, handler);
} }
static URL checkURL(URL u) throws IOException {
if (u != null) {
if (u.toExternalForm().indexOf('\n') > -1) {
throw new MalformedURLException("Illegal character in URL");
}
}
return u;
}
// For both copies of the file, uncomment one line and comment the other // For both copies of the file, uncomment one line and comment the other
HttpsURLConnectionImpl(URL u, Proxy p, Handler handler) throws IOException { HttpsURLConnectionImpl(URL u, Proxy p, Handler handler) throws IOException {
// HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException { // HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException {
super(u); super(checkURL(u));
delegate = new DelegateHttpsURLConnection(url, p, handler, this); delegate = new DelegateHttpsURLConnection(url, p, handler, this);
} }
......
/* /*
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, 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
...@@ -280,13 +280,14 @@ final class CardImpl extends Card { ...@@ -280,13 +280,14 @@ final class CardImpl extends Card {
} }
public String toString() { public String toString() {
return "PC/SC card in " + terminal.getName() return "PC/SC card in " + terminal.name
+ ", protocol " + getProtocol() + ", state " + state; + ", protocol " + getProtocol() + ", state " + state;
} }
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
if (state == State.OK) { if (state == State.OK) {
state = State.DISCONNECTED;
SCardDisconnect(cardId, SCARD_LEAVE_CARD); SCardDisconnect(cardId, SCARD_LEAVE_CARD);
} }
} finally { } finally {
......
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2017, 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
...@@ -33,6 +33,7 @@ import java.util.*; ...@@ -33,6 +33,7 @@ import java.util.*;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
import sun.net.util.IPAddressUtil;
import sun.security.util.*; import sun.security.util.*;
import sun.security.pkcs.PKCS9Attribute; import sun.security.pkcs.PKCS9Attribute;
...@@ -433,6 +434,7 @@ implements CertAttrSet<String>, Cloneable { ...@@ -433,6 +434,7 @@ implements CertAttrSet<String>, Cloneable {
X500Principal subjectPrincipal = cert.getSubjectX500Principal(); X500Principal subjectPrincipal = cert.getSubjectX500Principal();
X500Name subject = X500Name.asX500Name(subjectPrincipal); X500Name subject = X500Name.asX500Name(subjectPrincipal);
// Check subject as an X500Name
if (subject.isEmpty() == false) { if (subject.isEmpty() == false) {
if (verify(subject) == false) { if (verify(subject) == false) {
return false; return false;
...@@ -458,12 +460,51 @@ implements CertAttrSet<String>, Cloneable { ...@@ -458,12 +460,51 @@ implements CertAttrSet<String>, Cloneable {
"certificate: " + ce.getMessage()); "certificate: " + ce.getMessage());
} }
// If there are no subjectAlternativeNames, perform the special-case
// check where if the subjectName contains any EMAILADDRESS
// attributes, they must be checked against RFC822 constraints.
// If that passes, we're fine.
if (altNames == null) { if (altNames == null) {
return verifyRFC822SpecialCase(subject); altNames = new GeneralNames();
// RFC 5280 4.2.1.10:
// When constraints are imposed on the rfc822Name name form,
// but the certificate does not include a subject alternative name,
// the rfc822Name constraint MUST be applied to the attribute of
// type emailAddress in the subject distinguished name.
for (AVA ava : subject.allAvas()) {
ObjectIdentifier attrOID = ava.getObjectIdentifier();
if (attrOID.equals(PKCS9Attribute.EMAIL_ADDRESS_OID)) {
String attrValue = ava.getValueString();
if (attrValue != null) {
try {
altNames.add(new GeneralName(
new RFC822Name(attrValue)));
} catch (IOException ioe) {
continue;
}
}
}
}
}
// If there is no IPAddressName or DNSName in subjectAlternativeNames,
// see if the last CN inside subjectName can be used instead.
DerValue derValue = subject.findMostSpecificAttribute
(X500Name.commonName_oid);
String cn = derValue == null ? null : derValue.getAsString();
if (cn != null) {
try {
if (IPAddressUtil.isIPv4LiteralAddress(cn) ||
IPAddressUtil.isIPv6LiteralAddress(cn)) {
if (!hasNameType(altNames, GeneralNameInterface.NAME_IP)) {
altNames.add(new GeneralName(new IPAddressName(cn)));
}
} else {
if (!hasNameType(altNames, GeneralNameInterface.NAME_DNS)) {
altNames.add(new GeneralName(new DNSName(cn)));
}
}
} catch (IOException ioe) {
// OK, cn is neither IP nor DNS
}
} }
// verify each subjectAltName // verify each subjectAltName
...@@ -478,6 +519,15 @@ implements CertAttrSet<String>, Cloneable { ...@@ -478,6 +519,15 @@ implements CertAttrSet<String>, Cloneable {
return true; return true;
} }
private static boolean hasNameType(GeneralNames names, int type) {
for (GeneralName name : names.names()) {
if (name.getType() == type) {
return true;
}
}
return false;
}
/** /**
* check whether a name conforms to these NameConstraints. * check whether a name conforms to these NameConstraints.
* This involves verifying that the name is consistent with the * This involves verifying that the name is consistent with the
...@@ -559,37 +609,6 @@ implements CertAttrSet<String>, Cloneable { ...@@ -559,37 +609,6 @@ implements CertAttrSet<String>, Cloneable {
return true; return true;
} }
/**
* Perform the RFC 822 special case check. We have a certificate
* that does not contain any subject alternative names. Check that
* any EMAILADDRESS attributes in its subject name conform to these
* NameConstraints.
*
* @param subject the certificate's subject name
* @returns true if certificate verifies successfully
* @throws IOException on error
*/
public boolean verifyRFC822SpecialCase(X500Name subject) throws IOException {
for (AVA ava : subject.allAvas()) {
ObjectIdentifier attrOID = ava.getObjectIdentifier();
if (attrOID.equals((Object)PKCS9Attribute.EMAIL_ADDRESS_OID)) {
String attrValue = ava.getValueString();
if (attrValue != null) {
RFC822Name emailName;
try {
emailName = new RFC822Name(attrValue);
} catch (IOException ioe) {
continue;
}
if (!verify(emailName)) {
return(false);
}
}
}
}
return true;
}
/** /**
* Clone all objects that may be modified during certificate validation. * Clone all objects that may be modified during certificate validation.
*/ */
......
...@@ -900,7 +900,7 @@ void InSymbol(cmsIT8* it8) ...@@ -900,7 +900,7 @@ void InSymbol(cmsIT8* it8)
k = 0; k = 0;
NextCh(it8); NextCh(it8);
while (k < MAXSTR && it8->ch != sng) { while (k < (MAXSTR-1) && it8->ch != sng) {
if (it8->ch == '\n'|| it8->ch == '\r') k = MAXSTR+1; if (it8->ch == '\n'|| it8->ch == '\r') k = MAXSTR+1;
else { else {
...@@ -2053,14 +2053,18 @@ cmsBool HeaderSection(cmsIT8* it8) ...@@ -2053,14 +2053,18 @@ cmsBool HeaderSection(cmsIT8* it8)
static static
void ReadType(cmsIT8* it8, char* SheetTypePtr) void ReadType(cmsIT8* it8, char* SheetTypePtr)
{ {
cmsInt32Number cnt = 0;
// First line is a very special case. // First line is a very special case.
while (isseparator(it8->ch)) while (isseparator(it8->ch))
NextCh(it8); NextCh(it8);
while (it8->ch != '\r' && it8 ->ch != '\n' && it8->ch != '\t' && it8 -> ch != -1) { while (it8->ch != '\r' && it8 ->ch != '\n' && it8->ch != '\t' && it8 -> ch != 0) {
*SheetTypePtr++= (char) it8 ->ch; *SheetTypePtr++= (char) it8 ->ch;
if (cnt++ < MAXSTR)
*SheetTypePtr++= (char) it8 ->ch;
NextCh(it8); NextCh(it8);
} }
...@@ -2253,7 +2257,7 @@ void CookPointers(cmsIT8* it8) ...@@ -2253,7 +2257,7 @@ void CookPointers(cmsIT8* it8)
// that should be something like some printable characters plus a \n // that should be something like some printable characters plus a \n
// returns 0 if this is not like a CGATS, or an integer otherwise. This integer is the number of words in first line? // returns 0 if this is not like a CGATS, or an integer otherwise. This integer is the number of words in first line?
static static
int IsMyBlock(cmsUInt8Number* Buffer, int n) int IsMyBlock(const cmsUInt8Number* Buffer, int n)
{ {
int words = 1, space = 0, quot = 0; int words = 1, space = 0, quot = 0;
int i; int i;
...@@ -2317,7 +2321,7 @@ cmsBool IsMyFile(const char* FileName) ...@@ -2317,7 +2321,7 @@ cmsBool IsMyFile(const char* FileName)
// ---------------------------------------------------------- Exported routines // ---------------------------------------------------------- Exported routines
cmsHANDLE CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, void *Ptr, cmsUInt32Number len) cmsHANDLE CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, const void *Ptr, cmsUInt32Number len)
{ {
cmsHANDLE hIT8; cmsHANDLE hIT8;
cmsIT8* it8; cmsIT8* it8;
...@@ -2326,7 +2330,7 @@ cmsHANDLE CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, void *Ptr, cmsUInt3 ...@@ -2326,7 +2330,7 @@ cmsHANDLE CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, void *Ptr, cmsUInt3
_cmsAssert(Ptr != NULL); _cmsAssert(Ptr != NULL);
_cmsAssert(len != 0); _cmsAssert(len != 0);
type = IsMyBlock((cmsUInt8Number*)Ptr, len); type = IsMyBlock((const cmsUInt8Number*)Ptr, len);
if (type == 0) return NULL; if (type == 0) return NULL;
hIT8 = cmsIT8Alloc(ContextID); hIT8 = cmsIT8Alloc(ContextID);
......
...@@ -546,7 +546,11 @@ cmsBool GrowNamedColorList(cmsNAMEDCOLORLIST* v) ...@@ -546,7 +546,11 @@ cmsBool GrowNamedColorList(cmsNAMEDCOLORLIST* v)
size = v ->Allocated * 2; size = v ->Allocated * 2;
// Keep a maximum color lists can grow, 100K entries seems reasonable // Keep a maximum color lists can grow, 100K entries seems reasonable
if (size > 1024*100) return FALSE; if (size > 1024 * 100) {
_cmsFree(v->ContextID, (void*) v->List);
v->List = NULL;
return FALSE;
}
NewPtr = (_cmsNAMEDCOLOR*) _cmsRealloc(v ->ContextID, v ->List, size * sizeof(_cmsNAMEDCOLOR)); NewPtr = (_cmsNAMEDCOLOR*) _cmsRealloc(v ->ContextID, v ->List, size * sizeof(_cmsNAMEDCOLOR));
if (NewPtr == NULL) if (NewPtr == NULL)
...@@ -568,8 +572,11 @@ cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUIn ...@@ -568,8 +572,11 @@ cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUIn
v ->nColors = 0; v ->nColors = 0;
v ->ContextID = ContextID; v ->ContextID = ContextID;
while (v -> Allocated < n){ while (v -> Allocated < n) {
if (!GrowNamedColorList(v)) return NULL; if (!GrowNamedColorList(v)) {
_cmsFree(ContextID, (void*) v);
return NULL;
}
} }
strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix)-1); strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix)-1);
......
...@@ -1483,6 +1483,7 @@ cmsBool OptimizeByJoiningCurves(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUI ...@@ -1483,6 +1483,7 @@ cmsBool OptimizeByJoiningCurves(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUI
// LUT optimizes to nothing. Set the identity LUT // LUT optimizes to nothing. Set the identity LUT
cmsStageFree(ObtainedCurves); cmsStageFree(ObtainedCurves);
ObtainedCurves = NULL;
if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, cmsStageAllocIdentity(Dest ->ContextID, Src ->InputChannels))) if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, cmsStageAllocIdentity(Dest ->ContextID, Src ->InputChannels)))
goto Error; goto Error;
......
...@@ -4460,7 +4460,8 @@ void *Type_MPE_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU ...@@ -4460,7 +4460,8 @@ void *Type_MPE_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU
NewLUT = cmsPipelineAlloc(self ->ContextID, InputChans, OutputChans); NewLUT = cmsPipelineAlloc(self ->ContextID, InputChans, OutputChans);
if (NewLUT == NULL) return NULL; if (NewLUT == NULL) return NULL;
if (!_cmsReadUInt32Number(io, &ElementCount)) return NULL; if (!_cmsReadUInt32Number(io, &ElementCount)) goto Error;
if (!ReadPositionTable(self, io, ElementCount, BaseOffset, NewLUT, ReadMPEElem)) goto Error;
if (!ReadPositionTable(self, io, ElementCount, BaseOffset, NewLUT, ReadMPEElem)) { if (!ReadPositionTable(self, io, ElementCount, BaseOffset, NewLUT, ReadMPEElem)) {
if (NewLUT != NULL) cmsPipelineFree(NewLUT); if (NewLUT != NULL) cmsPipelineFree(NewLUT);
...@@ -4472,6 +4473,12 @@ void *Type_MPE_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU ...@@ -4472,6 +4473,12 @@ void *Type_MPE_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsU
*nItems = 1; *nItems = 1;
return NewLUT; return NewLUT;
// Error
Error:
if (NewLUT != NULL) cmsPipelineFree(NewLUT);
*nItems = 0;
return NULL;
cmsUNUSED_PARAMETER(SizeOfTag); cmsUNUSED_PARAMETER(SizeOfTag);
} }
......
...@@ -1836,7 +1836,7 @@ CMSAPI cmsInt32Number CMSEXPORT cmsIT8SetTable(cmsHANDLE hIT8, cmsUInt32Number ...@@ -1836,7 +1836,7 @@ CMSAPI cmsInt32Number CMSEXPORT cmsIT8SetTable(cmsHANDLE hIT8, cmsUInt32Number
// Persistence // Persistence
CMSAPI cmsHANDLE CMSEXPORT cmsIT8LoadFromFile(cmsContext ContextID, const char* cFileName); CMSAPI cmsHANDLE CMSEXPORT cmsIT8LoadFromFile(cmsContext ContextID, const char* cFileName);
CMSAPI cmsHANDLE CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, void *Ptr, cmsUInt32Number len); CMSAPI cmsHANDLE CMSEXPORT cmsIT8LoadFromMem(cmsContext ContextID, const void *Ptr, cmsUInt32Number len);
// CMSAPI cmsHANDLE CMSEXPORT cmsIT8LoadFromIOhandler(cmsContext ContextID, cmsIOHANDLER* io); // CMSAPI cmsHANDLE CMSEXPORT cmsIT8LoadFromIOhandler(cmsContext ContextID, cmsIOHANDLER* io);
CMSAPI cmsBool CMSEXPORT cmsIT8SaveToFile(cmsHANDLE hIT8, const char* cFileName); CMSAPI cmsBool CMSEXPORT cmsIT8SaveToFile(cmsHANDLE hIT8, const char* cFileName);
......
...@@ -61,29 +61,36 @@ INLINE void AwtCmdIDList::BuildFreeList(UINT first_index) ...@@ -61,29 +61,36 @@ INLINE void AwtCmdIDList::BuildFreeList(UINT first_index)
m_first_free = first_index; // head of the free list m_first_free = first_index; // head of the free list
} }
jboolean AwtCmdIDList::isFreeIDAvailable() {
CriticalSection::Lock l(m_lock);
if (m_first_free == -1) { // out of free ids
if (m_capacity == ARRAY_MAXIMUM_SIZE) {
return JNI_FALSE;
}
}
return JNI_TRUE;
}
// Assign an id to the object. Recycle the first free entry from the // Assign an id to the object. Recycle the first free entry from the
// head of the free list or allocate more memory for a new free list. // head of the free list or allocate more memory for a new free list.
UINT AwtCmdIDList::Add(AwtObject* obj) UINT AwtCmdIDList::Add(AwtObject* obj)
{ {
CriticalSection::Lock l(m_lock); CriticalSection::Lock l(m_lock);
if (!isFreeIDAvailable()) {
throw std::bad_alloc(); // fatal error
}
if (m_first_free == -1) { // out of free ids if (m_first_free == -1) { // out of free ids
if (m_capacity == ARRAY_MAXIMUM_SIZE) { // snarf a bigger arena
// Really bad - out of ids. Since we hardly can have *so* UINT old_capacity = m_capacity; // will be the first free entry
// many items simultaneously in existence, we have an id m_capacity += ARRAY_SIZE_INCREMENT;
// leak somewhere. if (m_capacity > ARRAY_MAXIMUM_SIZE)
DASSERT(FALSE); m_capacity = ARRAY_MAXIMUM_SIZE;
return 0; m_array = (CmdIDEntry *)SAFE_SIZE_ARRAY_REALLOC(safe_Realloc, m_array,
} m_capacity, sizeof(CmdIDEntry*));
else { // snarf a bigger arena BuildFreeList(old_capacity);
UINT old_capacity = m_capacity; // will be the first free entry
m_capacity += ARRAY_SIZE_INCREMENT;
if (m_capacity > ARRAY_MAXIMUM_SIZE)
m_capacity = ARRAY_MAXIMUM_SIZE;
m_array = (CmdIDEntry *)SAFE_SIZE_ARRAY_REALLOC(safe_Realloc, m_array,
m_capacity, sizeof(CmdIDEntry*));
BuildFreeList(old_capacity);
}
} }
DASSERT(m_first_free != -1); DASSERT(m_first_free != -1);
......
/* /*
* Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2017, 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
...@@ -38,6 +38,7 @@ public: ...@@ -38,6 +38,7 @@ public:
UINT Add(AwtObject* obj); UINT Add(AwtObject* obj);
AwtObject* Lookup(UINT id); AwtObject* Lookup(UINT id);
void Remove(UINT id); void Remove(UINT id);
jboolean isFreeIDAvailable();
CriticalSection m_lock; CriticalSection m_lock;
......
...@@ -57,15 +57,6 @@ typedef AwtObject* PDATA; ...@@ -57,15 +57,6 @@ typedef AwtObject* PDATA;
} \ } \
} }
#define JNI_CHECK_PEER_GOTO(peer, where) { \
JNI_CHECK_NULL_GOTO(peer, "peer", where); \
pData = JNI_GET_PDATA(peer); \
if (pData == NULL) { \
THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
goto where; \
} \
}
#define JNI_CHECK_NULL_RETURN(obj, msg) { \ #define JNI_CHECK_NULL_RETURN(obj, msg) { \
if (obj == NULL) { \ if (obj == NULL) { \
env->ExceptionClear(); \ env->ExceptionClear(); \
...@@ -74,15 +65,6 @@ typedef AwtObject* PDATA; ...@@ -74,15 +65,6 @@ typedef AwtObject* PDATA;
} \ } \
} }
#define JNI_CHECK_PEER_RETURN(peer) { \
JNI_CHECK_NULL_RETURN(peer, "peer"); \
pData = JNI_GET_PDATA(peer); \
if (pData == NULL) { \
THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
return; \
} \
}
#define JNI_CHECK_PEER_CREATION_RETURN(peer) { \ #define JNI_CHECK_PEER_CREATION_RETURN(peer) { \
if (peer == NULL ) { \ if (peer == NULL ) { \
return; \ return; \
...@@ -109,6 +91,33 @@ typedef AwtObject* PDATA; ...@@ -109,6 +91,33 @@ typedef AwtObject* PDATA;
} \ } \
} }
/**
* This macros must be used under SyncCall or on the Toolkit thread.
*/
#define JNI_CHECK_PEER_GOTO(peer, where) { \
JNI_CHECK_NULL_GOTO(peer, "peer", where); \
pData = JNI_GET_PDATA(peer); \
if (pData == NULL) { \
THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
goto where; \
} \
}
/**
* This macros must be used under SyncCall or on the Toolkit thread.
*/
#define JNI_CHECK_PEER_RETURN(peer) { \
JNI_CHECK_NULL_RETURN(peer, "peer"); \
pData = JNI_GET_PDATA(peer); \
if (pData == NULL) { \
THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
return; \
} \
}
/**
* This macros must be used under SyncCall or on the Toolkit thread.
*/
#define JNI_CHECK_PEER_RETURN_NULL(peer) { \ #define JNI_CHECK_PEER_RETURN_NULL(peer) { \
JNI_CHECK_NULL_RETURN_NULL(peer, "peer"); \ JNI_CHECK_NULL_RETURN_NULL(peer, "peer"); \
pData = JNI_GET_PDATA(peer); \ pData = JNI_GET_PDATA(peer); \
...@@ -118,6 +127,9 @@ typedef AwtObject* PDATA; ...@@ -118,6 +127,9 @@ typedef AwtObject* PDATA;
} \ } \
} }
/**
* This macros must be used under SyncCall or on the Toolkit thread.
*/
#define JNI_CHECK_PEER_RETURN_VAL(peer, val) { \ #define JNI_CHECK_PEER_RETURN_VAL(peer, val) { \
JNI_CHECK_NULL_RETURN_VAL(peer, "peer", val); \ JNI_CHECK_NULL_RETURN_VAL(peer, "peer", val); \
pData = JNI_GET_PDATA(peer); \ pData = JNI_GET_PDATA(peer); \
......
...@@ -65,6 +65,7 @@ LPCTSTR AwtButton::GetClassName() { ...@@ -65,6 +65,7 @@ LPCTSTR AwtButton::GetClassName() {
/* Create a new AwtButton object and window. */ /* Create a new AwtButton object and window. */
AwtButton* AwtButton::Create(jobject self, jobject parent) AwtButton* AwtButton::Create(jobject self, jobject parent)
{ {
DASSERT(AwtToolkit::IsMainThread());
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
/* the result */ /* the result */
...@@ -88,7 +89,6 @@ AwtButton* AwtButton::Create(jobject self, jobject parent) ...@@ -88,7 +89,6 @@ AwtButton* AwtButton::Create(jobject self, jobject parent)
JNI_CHECK_PEER_GOTO(parent, done); JNI_CHECK_PEER_GOTO(parent, done);
awtParent = (AwtCanvas*)pData; awtParent = (AwtCanvas*)pData;
JNI_CHECK_NULL_GOTO(awtParent, "awtParent", done);
target = env->GetObjectField(self, AwtObject::targetID); target = env->GetObjectField(self, AwtObject::targetID);
JNI_CHECK_NULL_GOTO(target, "target", done); JNI_CHECK_NULL_GOTO(target, "target", done);
...@@ -374,9 +374,6 @@ Java_sun_awt_windows_WButtonPeer_setLabel(JNIEnv *env, jobject self, ...@@ -374,9 +374,6 @@ Java_sun_awt_windows_WButtonPeer_setLabel(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(self);
SetLabelStruct *sls = new SetLabelStruct; SetLabelStruct *sls = new SetLabelStruct;
sls->button = env->NewGlobalRef(self); sls->button = env->NewGlobalRef(self);
sls->label = (label != NULL) ? (jstring)env->NewGlobalRef(label) : NULL; sls->label = (label != NULL) ? (jstring)env->NewGlobalRef(label) : NULL;
...@@ -398,14 +395,9 @@ Java_sun_awt_windows_WButtonPeer_create(JNIEnv *env, jobject self, ...@@ -398,14 +395,9 @@ Java_sun_awt_windows_WButtonPeer_create(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent( AwtToolkit::CreateComponent(
self, parent, (AwtToolkit::ComponentFactory)AwtButton::Create); self, parent, (AwtToolkit::ComponentFactory)AwtButton::Create);
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
...@@ -59,6 +59,7 @@ LPCTSTR AwtCanvas::GetClassName() { ...@@ -59,6 +59,7 @@ LPCTSTR AwtCanvas::GetClassName() {
*/ */
AwtCanvas* AwtCanvas::Create(jobject self, jobject hParent) AwtCanvas* AwtCanvas::Create(jobject self, jobject hParent)
{ {
DASSERT(AwtToolkit::IsMainThread());
TRY; TRY;
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
...@@ -74,12 +75,11 @@ AwtCanvas* AwtCanvas::Create(jobject self, jobject hParent) ...@@ -74,12 +75,11 @@ AwtCanvas* AwtCanvas::Create(jobject self, jobject hParent)
return NULL; return NULL;
} }
PDATA pData;
AwtComponent* parent; AwtComponent* parent;
JNI_CHECK_NULL_GOTO(hParent, "null hParent", done); JNI_CHECK_PEER_GOTO(hParent, done);
parent = (AwtCanvas*)pData;
parent = (AwtComponent*)JNI_GET_PDATA(hParent);
JNI_CHECK_NULL_GOTO(parent, "null parent", done);
target = env->GetObjectField(self, AwtObject::targetID); target = env->GetObjectField(self, AwtObject::targetID);
JNI_CHECK_NULL_GOTO(target, "null target", done); JNI_CHECK_NULL_GOTO(target, "null target", done);
...@@ -236,12 +236,9 @@ Java_sun_awt_windows_WCanvasPeer_create(JNIEnv *env, jobject self, ...@@ -236,12 +236,9 @@ Java_sun_awt_windows_WCanvasPeer_create(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtCanvas::Create); AwtCanvas::Create);
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
...@@ -70,6 +70,7 @@ LPCTSTR AwtCheckbox::GetClassName() { ...@@ -70,6 +70,7 @@ LPCTSTR AwtCheckbox::GetClassName() {
AwtCheckbox* AwtCheckbox::Create(jobject peer, jobject parent) AwtCheckbox* AwtCheckbox::Create(jobject peer, jobject parent)
{ {
DASSERT(AwtToolkit::IsMainThread());
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
jstring label = NULL; jstring label = NULL;
...@@ -81,11 +82,10 @@ AwtCheckbox* AwtCheckbox::Create(jobject peer, jobject parent) ...@@ -81,11 +82,10 @@ AwtCheckbox* AwtCheckbox::Create(jobject peer, jobject parent)
return NULL; return NULL;
} }
PDATA pData;
AwtComponent* awtParent; AwtComponent* awtParent;
JNI_CHECK_NULL_GOTO(parent, "null parent", done); JNI_CHECK_PEER_GOTO(parent, done);
awtParent = (AwtCanvas*)pData;
awtParent = (AwtComponent*)JNI_GET_PDATA(parent);
JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
target = env->GetObjectField(peer, AwtObject::targetID); target = env->GetObjectField(peer, AwtObject::targetID);
JNI_CHECK_NULL_GOTO(target, "null target", done); JNI_CHECK_NULL_GOTO(target, "null target", done);
...@@ -667,11 +667,10 @@ Java_sun_awt_windows_WCheckboxPeer_create(JNIEnv *env, jobject self, ...@@ -667,11 +667,10 @@ Java_sun_awt_windows_WCheckboxPeer_create(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtCheckbox::Create); AwtCheckbox::Create);
PDATA pData;
JNI_CHECK_PEER_CREATION_RETURN(self); JNI_CHECK_PEER_CREATION_RETURN(self);
#ifdef DEBUG #ifdef DEBUG
......
...@@ -104,7 +104,7 @@ void AwtChoice::Dispose() { ...@@ -104,7 +104,7 @@ void AwtChoice::Dispose() {
} }
AwtChoice* AwtChoice::Create(jobject peer, jobject parent) { AwtChoice* AwtChoice::Create(jobject peer, jobject parent) {
DASSERT(AwtToolkit::IsMainThread());
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
jobject target = NULL; jobject target = NULL;
...@@ -115,12 +115,10 @@ AwtChoice* AwtChoice::Create(jobject peer, jobject parent) { ...@@ -115,12 +115,10 @@ AwtChoice* AwtChoice::Create(jobject peer, jobject parent) {
if (env->EnsureLocalCapacity(1) < 0) { if (env->EnsureLocalCapacity(1) < 0) {
return NULL; return NULL;
} }
PDATA pData;
AwtCanvas* awtParent; AwtCanvas* awtParent;
JNI_CHECK_PEER_GOTO(parent, done);
JNI_CHECK_NULL_GOTO(parent, "null parent", done); awtParent = (AwtCanvas*)pData;
awtParent = (AwtCanvas*)JNI_GET_PDATA(parent);
JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
target = env->GetObjectField(peer, AwtObject::targetID); target = env->GetObjectField(peer, AwtObject::targetID);
JNI_CHECK_NULL_GOTO(target, "null target", done); JNI_CHECK_NULL_GOTO(target, "null target", done);
...@@ -829,12 +827,9 @@ Java_sun_awt_windows_WChoicePeer_create(JNIEnv *env, jobject self, ...@@ -829,12 +827,9 @@ Java_sun_awt_windows_WChoicePeer_create(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtChoice::Create); AwtChoice::Create);
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
...@@ -150,6 +150,11 @@ struct SetFocusStruct { ...@@ -150,6 +150,11 @@ struct SetFocusStruct {
jobject component; jobject component;
jboolean doSetFocus; jboolean doSetFocus;
}; };
// Struct for _SetParent function
struct SetParentStruct {
jobject component;
jobject parentComp;
};
/************************************************************************/ /************************************************************************/
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
...@@ -263,9 +268,6 @@ AwtComponent::~AwtComponent() ...@@ -263,9 +268,6 @@ AwtComponent::~AwtComponent()
{ {
DASSERT(AwtToolkit::IsMainThread()); DASSERT(AwtToolkit::IsMainThread());
/* Disconnect all links. */
UnlinkObjects();
/* /*
* All the messages for this component are processed, native * All the messages for this component are processed, native
* resources are freed, and Java object is not connected to * resources are freed, and Java object is not connected to
...@@ -277,6 +279,8 @@ AwtComponent::~AwtComponent() ...@@ -277,6 +279,8 @@ AwtComponent::~AwtComponent()
void AwtComponent::Dispose() void AwtComponent::Dispose()
{ {
DASSERT(AwtToolkit::IsMainThread());
// NOTE: in case the component/toplevel was focused, Java should // NOTE: in case the component/toplevel was focused, Java should
// have already taken care of proper transferring it or clearing. // have already taken care of proper transferring it or clearing.
...@@ -295,8 +299,10 @@ void AwtComponent::Dispose() ...@@ -295,8 +299,10 @@ void AwtComponent::Dispose()
/* Release global ref to input method */ /* Release global ref to input method */
SetInputMethod(NULL, TRUE); SetInputMethod(NULL, TRUE);
if (m_childList != NULL) if (m_childList != NULL) {
delete m_childList; delete m_childList;
m_childList = NULL;
}
DestroyDropTarget(); DestroyDropTarget();
ReleaseDragCapture(0); ReleaseDragCapture(0);
...@@ -319,6 +325,9 @@ void AwtComponent::Dispose() ...@@ -319,6 +325,9 @@ void AwtComponent::Dispose()
m_brushBackground = NULL; m_brushBackground = NULL;
} }
/* Disconnect all links. */
UnlinkObjects();
if (m_bPauseDestroy) { if (m_bPauseDestroy) {
// AwtComponent::WmNcDestroy could be released now // AwtComponent::WmNcDestroy could be released now
m_bPauseDestroy = FALSE; m_bPauseDestroy = FALSE;
...@@ -6138,21 +6147,36 @@ ret: ...@@ -6138,21 +6147,36 @@ ret:
return result; return result;
} }
void AwtComponent::SetParent(void * param) { void AwtComponent::_SetParent(void * param)
{
if (AwtToolkit::IsMainThread()) { if (AwtToolkit::IsMainThread()) {
AwtComponent** comps = (AwtComponent**)param; JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
if ((comps[0] != NULL) && (comps[1] != NULL)) { SetParentStruct *data = (SetParentStruct*) param;
HWND selfWnd = comps[0]->GetHWnd(); jobject self = data->component;
HWND parentWnd = comps[1]->GetHWnd(); jobject parent = data->parentComp;
if (::IsWindow(selfWnd) && ::IsWindow(parentWnd)) {
// Shouldn't trigger native focus change AwtComponent *awtComponent = NULL;
// (only the proxy may be the native focus owner). AwtComponent *awtParent = NULL;
::SetParent(selfWnd, parentWnd);
} PDATA pData;
JNI_CHECK_PEER_GOTO(self, ret);
awtComponent = (AwtComponent *)pData;
JNI_CHECK_PEER_GOTO(parent, ret);
awtParent = (AwtComponent *)pData;
HWND selfWnd = awtComponent->GetHWnd();
HWND parentWnd = awtParent->GetHWnd();
if (::IsWindow(selfWnd) && ::IsWindow(parentWnd)) {
// Shouldn't trigger native focus change
// (only the proxy may be the native focus owner).
::SetParent(selfWnd, parentWnd);
} }
delete[] comps; ret:
env->DeleteGlobalRef(self);
env->DeleteGlobalRef(parent);
delete data;
} else { } else {
AwtToolkit::GetInstance().InvokeFunction(AwtComponent::SetParent, param); AwtToolkit::GetInstance().InvokeFunction(AwtComponent::_SetParent, param);
} }
} }
...@@ -6979,15 +7003,12 @@ JNIEXPORT void JNICALL ...@@ -6979,15 +7003,12 @@ JNIEXPORT void JNICALL
Java_sun_awt_windows_WComponentPeer_pSetParent(JNIEnv* env, jobject self, jobject parent) { Java_sun_awt_windows_WComponentPeer_pSetParent(JNIEnv* env, jobject self, jobject parent) {
TRY; TRY;
typedef AwtComponent* PComponent; SetParentStruct * data = new SetParentStruct;
AwtComponent** comps = new PComponent[2]; data->component = env->NewGlobalRef(self);
AwtComponent* comp = (AwtComponent*)JNI_GET_PDATA(self); data->parentComp = env->NewGlobalRef(parent);
AwtComponent* parentComp = (AwtComponent*)JNI_GET_PDATA(parent);
comps[0] = comp;
comps[1] = parentComp;
AwtToolkit::GetInstance().SyncCall(AwtComponent::SetParent, comps); AwtToolkit::GetInstance().SyncCall(AwtComponent::_SetParent, data);
// comps is deleted in SetParent // global refs and data are deleted in SetParent
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
...@@ -665,6 +665,7 @@ public: ...@@ -665,6 +665,7 @@ public:
static void _RemoveNativeDropTarget(void *param); static void _RemoveNativeDropTarget(void *param);
static jintArray _CreatePrintedPixels(void *param); static jintArray _CreatePrintedPixels(void *param);
static jboolean _NativeHandlesWheelScrolling(void *param); static jboolean _NativeHandlesWheelScrolling(void *param);
static void _SetParent(void * param);
static void _SetRectangularShape(void *param); static void _SetRectangularShape(void *param);
static void _SetZOrder(void *param); static void _SetZOrder(void *param);
......
...@@ -112,12 +112,13 @@ AwtDialog* AwtDialog::Create(jobject peer, jobject parent) ...@@ -112,12 +112,13 @@ AwtDialog* AwtDialog::Create(jobject peer, jobject parent)
PDATA pData; PDATA pData;
AwtWindow* awtParent = NULL; AwtWindow* awtParent = NULL;
HWND hwndParent = NULL; HWND hwndParent = NULL;
target = env->GetObjectField(peer, AwtObject::targetID); target = env->GetObjectField(peer, AwtObject::targetID);
JNI_CHECK_NULL_GOTO(target, "null target", done); JNI_CHECK_NULL_GOTO(target, "null target", done);
if (parent != NULL) { if (parent != NULL) {
JNI_CHECK_PEER_GOTO(parent, done); JNI_CHECK_PEER_GOTO(parent, done);
awtParent = (AwtWindow *)(JNI_GET_PDATA(parent)); awtParent = (AwtWindow *)pData;
hwndParent = awtParent->GetHWnd(); hwndParent = awtParent->GetHWnd();
} else { } else {
// There is no way to prevent a parentless dialog from showing on // There is no way to prevent a parentless dialog from showing on
...@@ -784,11 +785,9 @@ Java_sun_awt_windows_WDialogPeer_createAwtDialog(JNIEnv *env, jobject self, ...@@ -784,11 +785,9 @@ Java_sun_awt_windows_WDialogPeer_createAwtDialog(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtDialog::Create); AwtDialog::Create);
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
...@@ -844,11 +844,16 @@ Java_sun_awt_windows_WFontMetrics_charsWidth(JNIEnv *env, jobject self, ...@@ -844,11 +844,16 @@ Java_sun_awt_windows_WFontMetrics_charsWidth(JNIEnv *env, jobject self,
if (str == NULL) { if (str == NULL) {
JNU_ThrowNullPointerException(env, "str argument"); JNU_ThrowNullPointerException(env, "str argument");
return NULL; return 0;
} }
if ((len < 0) || (off < 0) || (len + off > (env->GetArrayLength(str)))) { if ((len < 0) || (off < 0) || (len + off < 0) ||
(len + off > (env->GetArrayLength(str)))) {
JNU_ThrowArrayIndexOutOfBoundsException(env, "off/len argument"); JNU_ThrowArrayIndexOutOfBoundsException(env, "off/len argument");
return NULL; return 0;
}
if (off == env->GetArrayLength(str)) {
return 0;
} }
jchar *strp = new jchar[len]; jchar *strp = new jchar[len];
...@@ -880,12 +885,18 @@ Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self, ...@@ -880,12 +885,18 @@ Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self,
if (str == NULL) { if (str == NULL) {
JNU_ThrowNullPointerException(env, "bytes argument"); JNU_ThrowNullPointerException(env, "bytes argument");
return NULL; return 0;
} }
if ((len < 0) || (off < 0) || (len + off > (env->GetArrayLength(str)))) { if ((len < 0) || (off < 0) || (len + off < 0) ||
(len + off > (env->GetArrayLength(str)))) {
JNU_ThrowArrayIndexOutOfBoundsException(env, "off or len argument"); JNU_ThrowArrayIndexOutOfBoundsException(env, "off or len argument");
return NULL; return 0;
}
if (off == env->GetArrayLength(str)) {
return 0;
} }
char *pStrBody = NULL; char *pStrBody = NULL;
jint result = 0; jint result = 0;
try { try {
...@@ -893,12 +904,12 @@ Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self, ...@@ -893,12 +904,12 @@ Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self,
AwtFont::widthsID); AwtFont::widthsID);
if (array == NULL) { if (array == NULL) {
JNU_ThrowNullPointerException(env, "Can't access widths array."); JNU_ThrowNullPointerException(env, "Can't access widths array.");
return NULL; return 0;
} }
pStrBody = (char *)env->GetPrimitiveArrayCritical(str, 0); pStrBody = (char *)env->GetPrimitiveArrayCritical(str, 0);
if (pStrBody == NULL) { if (pStrBody == NULL) {
JNU_ThrowNullPointerException(env, "Can't access str bytes."); JNU_ThrowNullPointerException(env, "Can't access str bytes.");
return NULL; return 0;
} }
char *pStr = pStrBody + off; char *pStr = pStrBody + off;
...@@ -908,7 +919,7 @@ Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self, ...@@ -908,7 +919,7 @@ Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self,
if (widths == NULL) { if (widths == NULL) {
env->ReleasePrimitiveArrayCritical(str, pStrBody, 0); env->ReleasePrimitiveArrayCritical(str, pStrBody, 0);
JNU_ThrowNullPointerException(env, "Can't access widths."); JNU_ThrowNullPointerException(env, "Can't access widths.");
return NULL; return 0;
} }
for (; len; len--) { for (; len; len--) {
result += widths[*pStr++]; result += widths[*pStr++];
......
...@@ -1581,12 +1581,12 @@ void AwtFrame::_NotifyModalBlocked(void *param) ...@@ -1581,12 +1581,12 @@ void AwtFrame::_NotifyModalBlocked(void *param)
PDATA pData; PDATA pData;
pData = JNI_GET_PDATA(peer); JNI_CHECK_PEER_GOTO(peer, ret);
AwtFrame *f = (AwtFrame *)pData; AwtFrame *f = (AwtFrame *)pData;
// dialog here may be NULL, for example, if the blocker is a native dialog // dialog here may be NULL, for example, if the blocker is a native dialog
// however, we need to install/unistall modal hooks anyway // however, we need to install/unistall modal hooks anyway
pData = JNI_GET_PDATA(blockerPeer); JNI_CHECK_PEER_GOTO(blockerPeer, ret);
AwtDialog *d = (AwtDialog *)pData; AwtDialog *d = (AwtDialog *)pData;
if ((f != NULL) && ::IsWindow(f->GetHWnd())) if ((f != NULL) && ::IsWindow(f->GetHWnd()))
...@@ -1638,7 +1638,7 @@ void AwtFrame::_NotifyModalBlocked(void *param) ...@@ -1638,7 +1638,7 @@ void AwtFrame::_NotifyModalBlocked(void *param)
} }
} }
} }
ret:
env->DeleteGlobalRef(self); env->DeleteGlobalRef(self);
env->DeleteGlobalRef(peer); env->DeleteGlobalRef(peer);
env->DeleteGlobalRef(blockerPeer); env->DeleteGlobalRef(blockerPeer);
...@@ -1810,8 +1810,6 @@ Java_sun_awt_windows_WFramePeer_createAwtFrame(JNIEnv *env, jobject self, ...@@ -1810,8 +1810,6 @@ Java_sun_awt_windows_WFramePeer_createAwtFrame(JNIEnv *env, jobject self,
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtFrame::Create); AwtFrame::Create);
PDATA pData;
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
...@@ -1925,8 +1923,6 @@ Java_sun_awt_windows_WEmbeddedFramePeer_create(JNIEnv *env, jobject self, ...@@ -1925,8 +1923,6 @@ Java_sun_awt_windows_WEmbeddedFramePeer_create(JNIEnv *env, jobject self,
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtFrame::Create); AwtFrame::Create);
PDATA pData;
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
...@@ -80,7 +80,7 @@ AwtLabel* AwtLabel::Create(jobject labelPeer, jobject parent) ...@@ -80,7 +80,7 @@ AwtLabel* AwtLabel::Create(jobject labelPeer, jobject parent)
JNI_CHECK_PEER_GOTO(parent, done); JNI_CHECK_PEER_GOTO(parent, done);
awtParent = (AwtCanvas*)pData; awtParent = (AwtCanvas*)pData;
JNI_CHECK_NULL_GOTO(awtParent, "awtParent", done);
target = env->GetObjectField(labelPeer, AwtObject::targetID); target = env->GetObjectField(labelPeer, AwtObject::targetID);
JNI_CHECK_NULL_GOTO(target, "target", done); JNI_CHECK_NULL_GOTO(target, "target", done);
...@@ -392,12 +392,9 @@ Java_sun_awt_windows_WLabelPeer_create(JNIEnv *env, jobject self, ...@@ -392,12 +392,9 @@ Java_sun_awt_windows_WLabelPeer_create(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtLabel::Create); AwtLabel::Create);
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
...@@ -89,10 +89,9 @@ AwtList* AwtList::Create(jobject peer, jobject parent) ...@@ -89,10 +89,9 @@ AwtList* AwtList::Create(jobject peer, jobject parent)
PDATA pData; PDATA pData;
AwtCanvas* awtParent; AwtCanvas* awtParent;
JNI_CHECK_PEER_GOTO(parent, done);
JNI_CHECK_PEER_GOTO(parent, done);
awtParent = (AwtCanvas*)pData; awtParent = (AwtCanvas*)pData;
JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
/* target is Hjava_awt_List * */ /* target is Hjava_awt_List * */
target = env->GetObjectField(peer, AwtObject::targetID); target = env->GetObjectField(peer, AwtObject::targetID);
...@@ -928,9 +927,6 @@ Java_sun_awt_windows_WListPeer_deselect(JNIEnv *env, jobject self, ...@@ -928,9 +927,6 @@ Java_sun_awt_windows_WListPeer_deselect(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(self);
SelectElementStruct *ses = new SelectElementStruct; SelectElementStruct *ses = new SelectElementStruct;
ses->list = env->NewGlobalRef(self); ses->list = env->NewGlobalRef(self);
ses->index = pos; ses->index = pos;
...@@ -994,11 +990,8 @@ Java_sun_awt_windows_WListPeer_create(JNIEnv *env, jobject self, ...@@ -994,11 +990,8 @@ Java_sun_awt_windows_WListPeer_create(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory)AwtList::Create); (AwtToolkit::ComponentFactory)AwtList::Create);
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
/* /*
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2017, 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
...@@ -217,6 +217,10 @@ AwtMenuItem* AwtMenuItem::Create(jobject peer, jobject menuPeer) ...@@ -217,6 +217,10 @@ AwtMenuItem* AwtMenuItem::Create(jobject peer, jobject menuPeer)
if (env->EnsureLocalCapacity(1) < 0) { if (env->EnsureLocalCapacity(1) < 0) {
return NULL; return NULL;
} }
if (!AwtToolkit::GetInstance().isFreeIDAvailable()) {
return NULL;
}
JNI_CHECK_NULL_RETURN_NULL(menuPeer, "peer"); JNI_CHECK_NULL_RETURN_NULL(menuPeer, "peer");
/* target is a java.awt.MenuItem */ /* target is a java.awt.MenuItem */
......
...@@ -96,10 +96,9 @@ AwtScrollPane* AwtScrollPane::Create(jobject self, jobject parent) ...@@ -96,10 +96,9 @@ AwtScrollPane* AwtScrollPane::Create(jobject self, jobject parent)
PDATA pData; PDATA pData;
AwtComponent* awtParent; AwtComponent* awtParent;
JNI_CHECK_PEER_GOTO(parent, done);
JNI_CHECK_PEER_GOTO(parent, done);
awtParent = (AwtComponent*)pData; awtParent = (AwtComponent*)pData;
JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
target = env->GetObjectField(self, AwtObject::targetID); target = env->GetObjectField(self, AwtObject::targetID);
JNI_CHECK_NULL_GOTO(target, "null target", done); JNI_CHECK_NULL_GOTO(target, "null target", done);
...@@ -679,11 +678,10 @@ Java_sun_awt_windows_WScrollPanePeer_create(JNIEnv *env, jobject self, ...@@ -679,11 +678,10 @@ Java_sun_awt_windows_WScrollPanePeer_create(JNIEnv *env, jobject self,
DTRACE_PRINTLN2("%x: WScrollPanePeer.create(%x)", self, parent); DTRACE_PRINTLN2("%x: WScrollPanePeer.create(%x)", self, parent);
PDATA pData;
JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtScrollPane::Create); AwtScrollPane::Create);
PDATA pData;
JNI_CHECK_PEER_CREATION_RETURN(self); JNI_CHECK_PEER_CREATION_RETURN(self);
((AwtScrollPane*)pData)->VerifyState(); ((AwtScrollPane*)pData)->VerifyState();
......
...@@ -38,7 +38,11 @@ struct SetValuesStruct { ...@@ -38,7 +38,11 @@ struct SetValuesStruct {
jint value; jint value;
jint visible; jint visible;
jint min, max; jint min, max;
};
// struct for _SetLineIncrement()/_SetPageIncrement() methods
struct SetIncrementStruct {
jobject scrollbar;
jint increment;
}; };
/************************************************************************ /************************************************************************
* AwtScrollbar fields * AwtScrollbar fields
...@@ -108,10 +112,9 @@ AwtScrollbar::Create(jobject peer, jobject parent) ...@@ -108,10 +112,9 @@ AwtScrollbar::Create(jobject peer, jobject parent)
PDATA pData; PDATA pData;
AwtCanvas* awtParent; AwtCanvas* awtParent;
JNI_CHECK_PEER_GOTO(parent, done);
JNI_CHECK_PEER_GOTO(parent, done);
awtParent = (AwtCanvas*)pData; awtParent = (AwtCanvas*)pData;
JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
target = env->GetObjectField(peer, AwtObject::targetID); target = env->GetObjectField(peer, AwtObject::targetID);
JNI_CHECK_NULL_GOTO(target, "null target", done); JNI_CHECK_NULL_GOTO(target, "null target", done);
...@@ -471,6 +474,52 @@ ret: ...@@ -471,6 +474,52 @@ ret:
delete svs; delete svs;
} }
void AwtScrollbar::_SetLineIncrement(void *param)
{
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
SetIncrementStruct *sis = (SetIncrementStruct *)param;
jobject self = sis->scrollbar;
jint increment = sis->increment;
AwtScrollbar *sb = NULL;
PDATA pData;
JNI_CHECK_PEER_GOTO(self, ret);
sb = (AwtScrollbar *)pData;
if (::IsWindow(sb->GetHWnd()))
{
sb->SetLineIncrement(increment);
}
ret:
env->DeleteGlobalRef(self);
delete sis;
}
void AwtScrollbar::_SetPageIncrement(void *param)
{
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
SetIncrementStruct *sis = (SetIncrementStruct *)param;
jobject self = sis->scrollbar;
jint increment = sis->increment;
AwtScrollbar *sb = NULL;
PDATA pData;
JNI_CHECK_PEER_GOTO(self, ret);
sb = (AwtScrollbar *)pData;
if (::IsWindow(sb->GetHWnd()))
{
sb->SetPageIncrement(increment);
}
ret:
env->DeleteGlobalRef(self);
delete sis;
}
/************************************************************************ /************************************************************************
* Scrollbar native methods * Scrollbar native methods
*/ */
...@@ -546,10 +595,12 @@ Java_sun_awt_windows_WScrollbarPeer_setLineIncrement(JNIEnv *env, jobject self, ...@@ -546,10 +595,12 @@ Java_sun_awt_windows_WScrollbarPeer_setLineIncrement(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData; SetIncrementStruct *sis = new SetIncrementStruct;
JNI_CHECK_PEER_RETURN(self); sis->scrollbar = env->NewGlobalRef(self);
AwtScrollbar* c = (AwtScrollbar*)pData; sis->increment = increment;
c->SetLineIncrement(increment);
AwtToolkit::GetInstance().SyncCall(AwtScrollbar::_SetLineIncrement, sis);
// global ref and svs are deleted in _SetValues
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
...@@ -565,10 +616,12 @@ Java_sun_awt_windows_WScrollbarPeer_setPageIncrement(JNIEnv *env, jobject self, ...@@ -565,10 +616,12 @@ Java_sun_awt_windows_WScrollbarPeer_setPageIncrement(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData; SetIncrementStruct *sis = new SetIncrementStruct;
JNI_CHECK_PEER_RETURN(self); sis->scrollbar = env->NewGlobalRef(self);
AwtScrollbar* c = (AwtScrollbar*)pData; sis->increment = increment;
c->SetPageIncrement(increment);
AwtToolkit::GetInstance().SyncCall(AwtScrollbar::_SetPageIncrement, sis);
// global ref and svs are deleted in _SetValues
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
...@@ -584,12 +637,9 @@ Java_sun_awt_windows_WScrollbarPeer_create(JNIEnv *env, jobject self, ...@@ -584,12 +637,9 @@ Java_sun_awt_windows_WScrollbarPeer_create(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtScrollbar::Create); AwtScrollbar::Create);
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
...@@ -77,6 +77,8 @@ public: ...@@ -77,6 +77,8 @@ public:
INLINE virtual BOOL IsScrollbar() { return TRUE; } INLINE virtual BOOL IsScrollbar() { return TRUE; }
static void _SetLineIncrement(void *param);
static void _SetPageIncrement(void *param);
// invoked on Toolkit thread // invoked on Toolkit thread
static void _SetValues(void *param); static void _SetValues(void *param);
......
...@@ -543,12 +543,9 @@ Java_sun_awt_windows_WTextAreaPeer_create(JNIEnv *env, jobject self, ...@@ -543,12 +543,9 @@ Java_sun_awt_windows_WTextAreaPeer_create(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtTextArea::Create); AwtTextArea::Create);
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
...@@ -95,10 +95,9 @@ AwtTextComponent* AwtTextComponent::Create(jobject peer, jobject parent, BOOL is ...@@ -95,10 +95,9 @@ AwtTextComponent* AwtTextComponent::Create(jobject peer, jobject parent, BOOL is
PDATA pData; PDATA pData;
AwtCanvas* awtParent; AwtCanvas* awtParent;
JNI_CHECK_PEER_GOTO(parent, done);
JNI_CHECK_PEER_GOTO(parent, done);
awtParent = (AwtCanvas*)pData; awtParent = (AwtCanvas*)pData;
JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
target = env->GetObjectField(peer, AwtObject::targetID); target = env->GetObjectField(peer, AwtObject::targetID);
JNI_CHECK_NULL_GOTO(target, "null target", done); JNI_CHECK_NULL_GOTO(target, "null target", done);
......
...@@ -301,12 +301,9 @@ Java_sun_awt_windows_WTextFieldPeer_create(JNIEnv *env, jobject self, ...@@ -301,12 +301,9 @@ Java_sun_awt_windows_WTextFieldPeer_create(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtTextField::Create); AwtTextField::Create);
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
/* /*
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2017, 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
...@@ -1583,6 +1583,11 @@ void AwtToolkit::SyncCall(void (*ftn)(void)) { ...@@ -1583,6 +1583,11 @@ void AwtToolkit::SyncCall(void (*ftn)(void)) {
} }
} }
jboolean AwtToolkit::isFreeIDAvailable()
{
return m_cmdIDs->isFreeIDAvailable();
}
UINT AwtToolkit::CreateCmdID(AwtObject* object) UINT AwtToolkit::CreateCmdID(AwtObject* object)
{ {
return m_cmdIDs->Add(object); return m_cmdIDs->Add(object);
......
/* /*
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2017, 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
...@@ -317,6 +317,8 @@ public: ...@@ -317,6 +317,8 @@ public:
BOOL PreProcessMouseMsg(class AwtComponent* p, MSG& msg); BOOL PreProcessMouseMsg(class AwtComponent* p, MSG& msg);
BOOL PreProcessKeyMsg(class AwtComponent* p, MSG& msg); BOOL PreProcessKeyMsg(class AwtComponent* p, MSG& msg);
/* Checks that an free ID exists. */
jboolean isFreeIDAvailable();
/* Create an ID which maps to an AwtObject pointer, such as a menu. */ /* Create an ID which maps to an AwtObject pointer, such as a menu. */
UINT CreateCmdID(AwtObject* object); UINT CreateCmdID(AwtObject* object);
......
...@@ -3246,12 +3246,9 @@ Java_sun_awt_windows_WWindowPeer_createAwtWindow(JNIEnv *env, jobject self, ...@@ -3246,12 +3246,9 @@ Java_sun_awt_windows_WWindowPeer_createAwtWindow(JNIEnv *env, jobject self,
{ {
TRY; TRY;
PDATA pData;
// JNI_CHECK_PEER_RETURN(parent);
AwtToolkit::CreateComponent(self, parent, AwtToolkit::CreateComponent(self, parent,
(AwtToolkit::ComponentFactory) (AwtToolkit::ComponentFactory)
AwtWindow::Create); AwtWindow::Create);
JNI_CHECK_PEER_CREATION_RETURN(self);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
/* /*
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2017, 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
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 6741606 7146431 8000450 8019830 8022945 8027144 8041633 * @bug 6741606 7146431 8000450 8019830 8022945 8027144 8041633 8179423
* @summary Make sure all restricted packages listed in the package.access * @summary Make sure all restricted packages listed in the package.access
* property in the java.security file are blocked * property in the java.security file are blocked
* @run main/othervm CheckPackageAccess * @run main/othervm CheckPackageAccess
...@@ -74,6 +74,8 @@ public class CheckPackageAccess { ...@@ -74,6 +74,8 @@ public class CheckPackageAccess {
"com.sun.org.apache.xalan.internal.xsltc.trax.", "com.sun.org.apache.xalan.internal.xsltc.trax.",
"com.sun.org.apache.xalan.internal.xsltc.util.", "com.sun.org.apache.xalan.internal.xsltc.util.",
"com.sun.org.apache.xml.internal.res.", "com.sun.org.apache.xml.internal.res.",
"com.sun.org.apache.xml.internal.resolver.helpers.",
"com.sun.org.apache.xml.internal.resolver.readers.",
"com.sun.org.apache.xml.internal.security.", "com.sun.org.apache.xml.internal.security.",
"com.sun.org.apache.xml.internal.serializer.utils.", "com.sun.org.apache.xml.internal.serializer.utils.",
"com.sun.org.apache.xml.internal.utils.", "com.sun.org.apache.xml.internal.utils.",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册