diff --git a/make/common/shared/Sanity.gmk b/make/common/shared/Sanity.gmk index e7e3978bc8dabdaca4de1f257633b8c4b8b8aa06..5fb51fe3cfe667432f1a1b9d6608bc47d0c5e48d 100644 --- a/make/common/shared/Sanity.gmk +++ b/make/common/shared/Sanity.gmk @@ -687,13 +687,13 @@ endif ###################################################### sane-alt_outputdir: ifdef ALT_OUTPUTDIR - @if [ `$(ECHO) $(subst \,/,$(ALT_OUTPUTDIR)) | $(EGREP) -ci '^([a-z]:)?/'` -ne 1 ]; then \ + @if [ `$(ECHO) $(subst \,/,$(ALT_OUTPUTDIR)) | $(EGREP) -c '^([A-Za-z]:)?/'` -ne 1 ]; then \ $(ECHO) "ERROR: ALT_OUTPUTDIR must be an Absolute Path Name, \n" \ " not a Relative Path Name. \n" \ "" >> $(ERROR_FILE) ; \ fi ifeq ($(PLATFORM), windows) - @if [ `$(ECHO) $(subst \,/,$(ALT_OUTPUTDIR)) | $(EGREP) -ci '^([a-z]:)'` -ne 1 ]; then \ + @if [ `$(ECHO) $(subst \,/,$(ALT_OUTPUTDIR)) | $(EGREP) -c '^([A-Za-z]:)'` -ne 1 ]; then \ $(ECHO) "ERROR: On windows, ALT_OUTPUTDIR must contain the drive letter. \n" \ "" >> $(ERROR_FILE) ; \ fi @@ -742,7 +742,7 @@ sane-outputdir: ###################################################### sane-alt_bootdir: ifdef ALT_BOOTDIR - @if [ `$(ECHO) $(subst \,/,$(ALT_BOOTDIR)) | $(EGREP) -ci '^([a-z]:)?/'` -ne 1 ]; then \ + @if [ `$(ECHO) $(subst \,/,$(ALT_BOOTDIR)) | $(EGREP) -c '^([A-Za-z]:)?/'` -ne 1 ]; then \ $(ECHO) "ERROR: ALT_BOOTDIR must be an Absolute Path Name, \n" \ " not a Relative Path Name. \n" \ " The current value of ALT_BOOTDIR is \n" \ @@ -772,7 +772,7 @@ sane-bootdir: ###################################################### sane-local-bootdir: ifeq ($(PLATFORM), windows) - @if [ `$(ECHO) $(BOOTDIR) | $(EGREP) -ci '^J:'` -ne 0 ]; then \ + @if [ `$(ECHO) $(BOOTDIR) | $(EGREP) -c '^[jJ]:'` -ne 0 ]; then \ $(ECHO) "WARNING: Your BOOTDIR is located on the J: drive. Often the J:\n" \ " drive is mapped over a network. Using a mapped drive for\n" \ " the BOOTDIR may significantly slow down the build process.\n" \ @@ -789,7 +789,7 @@ endif ###################################################### sane-cacerts: ifdef ALT_CACERTS_FILE - @if [ `$(ECHO) $(subst \,/,$(ALT_CACERTS_FILE)) | $(EGREP) -ci '^([a-z]:)?/'` -ne 1 ]; then \ + @if [ `$(ECHO) $(subst \,/,$(ALT_CACERTS_FILE)) | $(EGREP) -c '^([A-Za-z]:)?/'` -ne 1 ]; then \ $(ECHO) "ERROR: ALT_CACERTS_FILE must be an Absolute Path Name, \n" \ " not a Relative Path Name. \n" \ " The current value of ALT_CACERTS_FILE is \n" \ @@ -1538,7 +1538,7 @@ endif sane-mozilla: ifeq ($(ARCH_DATA_MODEL), 32) ifdef ALT_MOZILLA_HEADERS_PATH - @if [ `$(ECHO) $(subst \,/,$(ALT_MOZILLA_HEADERS_PATH)) | $(EGREP) -ci '^([a-z]:)?/'` -ne 1 ]; then \ + @if [ `$(ECHO) $(subst \,/,$(ALT_MOZILLA_HEADERS_PATH)) | $(EGREP) -c '^([A-Za-z]:)?/'` -ne 1 ]; then \ $(ECHO) "ERROR: ALT_MOZILLA_HEADERS_PATH must be an Absolute Path Name, \n" \ " not a Relative Path Name. \n" \ " The current value of ALT_MOZILLA_HEADERS_PATH is \n" \ diff --git a/make/modules/tools/Makefile b/make/modules/tools/Makefile index 115411d360ae882fb2cad11e6a097f04183222fe..415c07d7563ddb846e299b1ec32c5f77fe506c86 100644 --- a/make/modules/tools/Makefile +++ b/make/modules/tools/Makefile @@ -135,9 +135,8 @@ $(BUILDTOOLCLASSDIR)/%.class : $(BUILDTOOL_SOURCE_ROOT)/%.java $(CLASSANALYZER_JAR_FILE): $(BUILDTOOL_MANIFEST_FILE) $(FILES_class) @$(prep-target) - $(CD) $(BUILDTOOLCLASSDIR) && \ - $(BOOT_JAR_CMD) cfm $@ $(BUILDTOOL_MANIFEST_FILE) \ - $(PKGDIR) $(BOOT_JAR_JFLAGS) || $(RM) $@ + $(BOOT_JAR_CMD) cfm $@ $(BUILDTOOL_MANIFEST_FILE) \ + -C $(BUILDTOOLCLASSDIR) $(PKGDIR) $(BOOT_JAR_JFLAGS) || $(RM) $@ @$(java-vm-cleanup) $(BUILDTOOLJARDIR)/classfile.jar: $(FILES_classfile_class) diff --git a/src/share/classes/com/sun/jndi/ldap/Filter.java b/src/share/classes/com/sun/jndi/ldap/Filter.java index 17f5eb220381e1fc5962ed55747360619332e053..1dfc46c24315a2b6beed4f0a3185aa40a5b22330 100644 --- a/src/share/classes/com/sun/jndi/ldap/Filter.java +++ b/src/share/classes/com/sun/jndi/ldap/Filter.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1999-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,6 +33,7 @@ import java.io.IOException; /** * LDAP (RFC-1960) and LDAPv3 (RFC-2254) search filters. * + * @author Xuelei Fan * @author Vincent Ryan * @author Jagane Sundar * @author Rosanna Lee @@ -258,7 +259,7 @@ final class Filter { byte[] answer = new byte[j]; System.arraycopy(tbuf, 0, answer, 0, j); if (dbg) { - Ber.dumpBER(System.err, null, answer, 0, j); + Ber.dumpBER(System.err, "", answer, 0, j); } return answer; } @@ -330,7 +331,7 @@ final class Filter { } - valueStart = eq + 1; // value starts after equal sign + valueStart = eq + 1; // value starts after equal sign valueEnd = filtEnd; typeStart = filtStart; // beginning of string @@ -355,20 +356,199 @@ final class Filter { break; default: typeEnd = eq; + //initializing ftype to make the compiler happy + ftype = 0x00; + break; + } + + if (dbg) { + System.err.println("type: " + typeStart + ", " + typeEnd); + System.err.println("value: " + valueStart + ", " + valueEnd); + } + + // check validity of type + // + // RFC4512 defines the type as the following ABNF: + // attr = attributedescription + // attributedescription = attributetype options + // attributetype = oid + // oid = descr / numericoid + // descr = keystring + // keystring = leadkeychar *keychar + // leadkeychar = ALPHA + // keychar = ALPHA / DIGIT / HYPHEN + // numericoid = number 1*( DOT number ) + // number = DIGIT / ( LDIGIT 1*DIGIT ) + // options = *( SEMI option ) + // option = 1*keychar + // + // And RFC4515 defines the extensible type as the following ABNF: + // attr [dnattrs] [matchingrule] / [dnattrs] matchingrule + int optionsStart = -1; + int extensibleStart = -1; + if ((filter[typeStart] >= '0' && filter[typeStart] <= '9') || + (filter[typeStart] >= 'A' && filter[typeStart] <= 'Z') || + (filter[typeStart] >= 'a' && filter[typeStart] <= 'z')) { + + boolean isNumericOid = + filter[typeStart] >= '0' && filter[typeStart] <= '9'; + for (int i = typeStart + 1; i < typeEnd; i++) { + // ';' is an indicator of attribute options + if (filter[i] == ';') { + if (isNumericOid && filter[i - 1] == '.') { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + + // attribute options + optionsStart = i; + break; + } + + // ':' is an indicator of extensible rules + if (filter[i] == ':' && ftype == LDAP_FILTER_EXT) { + if (isNumericOid && filter[i - 1] == '.') { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + + // extensible matching + extensibleStart = i; + break; + } + + if (isNumericOid) { + // numeric object identifier + if ((filter[i] == '.' && filter[i - 1] == '.') || + (filter[i] != '.' && + !(filter[i] >= '0' && filter[i] <= '9'))) { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + } else { + // descriptor + if (filter[i] != '-' && + !(filter[i] >= '0' && filter[i] <= '9') && + !(filter[i] >= 'A' && filter[i] <= 'Z') && + !(filter[i] >= 'a' && filter[i] <= 'z')) { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + } + } + } else if (ftype == LDAP_FILTER_EXT && filter[typeStart] == ':') { + // extensible matching + extensibleStart = typeStart; + } else { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + + // check attribute options + if (optionsStart > 0) { + for (int i = optionsStart + 1; i < typeEnd; i++) { + if (filter[i] == ';') { + if (filter[i - 1] == ';') { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + continue; + } + + // ':' is an indicator of extensible rules + if (filter[i] == ':' && ftype == LDAP_FILTER_EXT) { + if (filter[i - 1] == ';') { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + + // extensible matching + extensibleStart = i; + break; + } + + if (filter[i] != '-' && + !(filter[i] >= '0' && filter[i] <= '9') && + !(filter[i] >= 'A' && filter[i] <= 'Z') && + !(filter[i] >= 'a' && filter[i] <= 'z')) { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + } + } + + // check extensible matching + if (extensibleStart > 0) { + boolean isMatchingRule = false; + for (int i = extensibleStart + 1; i < typeEnd; i++) { + if (filter[i] == ':') { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } else if ((filter[i] >= '0' && filter[i] <= '9') || + (filter[i] >= 'A' && filter[i] <= 'Z') || + (filter[i] >= 'a' && filter[i] <= 'z')) { + boolean isNumericOid = filter[i] >= '0' && filter[i] <= '9'; + i++; + for (int j = i; j < typeEnd; j++, i++) { + // allows no more than two extensible rules + if (filter[j] == ':') { + if (isMatchingRule) { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + if (isNumericOid && filter[j - 1] == '.') { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + + isMatchingRule = true; + break; + } + + if (isNumericOid) { + // numeric object identifier + if ((filter[j] == '.' && filter[j - 1] == '.') || + (filter[j] != '.' && + !(filter[j] >= '0' && filter[j] <= '9'))) { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + } else { + // descriptor + if (filter[j] != '-' && + !(filter[j] >= '0' && filter[j] <= '9') && + !(filter[j] >= 'A' && filter[j] <= 'Z') && + !(filter[j] >= 'a' && filter[j] <= 'z')) { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + } + } + } else { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + } + } + + // ensure the latest byte is not isolated + if (filter[typeEnd - 1] == '.' || filter[typeEnd - 1] == ';' || + filter[typeEnd - 1] == ':') { + throw new InvalidSearchFilterException( + "invalid attribute description"); + } + + if (typeEnd == eq) { // filter type is of "equal" if (findUnescaped(filter, '*', valueStart, valueEnd) == -1) { ftype = LDAP_FILTER_EQUALITY; - } else if (filter[valueStart] == '*' && valueStart == (valueEnd - 1)) { + } else if (filter[valueStart] == '*' && + valueStart == (valueEnd - 1)) { ftype = LDAP_FILTER_PRESENT; } else { encodeSubstringFilter(ber, filter, typeStart, typeEnd, valueStart, valueEnd); return; } - break; - } - if (dbg) { - System.err.println("type: " + typeStart + ", " + typeEnd); - System.err.println("value: " + valueStart + ", " + valueEnd); } if (ftype == LDAP_FILTER_PRESENT) { @@ -379,7 +559,7 @@ final class Filter { } else { ber.beginSeq(ftype); ber.encodeOctetString(filter, Ber.ASN_OCTET_STR, - typeStart, typeEnd-typeStart); + typeStart, typeEnd - typeStart); ber.encodeOctetString( unescapeFilterValue(filter, valueStart, valueEnd), Ber.ASN_OCTET_STR); @@ -623,7 +803,8 @@ final class Filter { // //////////////////////////////////////////////////////////////////////////// - private static final boolean dbg = false; + // private static final boolean dbg = false; + private static final boolean dbg = true; private static int dbgIndent = 0; private static void dprint(String msg) { diff --git a/src/share/classes/java/lang/Iterable.java b/src/share/classes/java/lang/Iterable.java index 9463feeab4f482ce01ac66807cfda48a2079c864..0b1e9548a522df470482cbcd82d971e36a5c6ccb 100644 --- a/src/share/classes/java/lang/Iterable.java +++ b/src/share/classes/java/lang/Iterable.java @@ -27,8 +27,12 @@ package java.lang; import java.util.Iterator; -/** Implementing this interface allows an object to be the target of - * the "foreach" statement. +/** + * Implementing this interface allows an object to be the target of + * the "foreach" statement. + * + * @param the type of elements returned by the iterator + * * @since 1.5 */ public interface Iterable { diff --git a/src/share/classes/java/lang/String.java b/src/share/classes/java/lang/String.java index 6aaf7684bf3fc1d5a4d6d9ef403e9359f054e19d..2aead0f545d8038b2b0bfab8e3d43f4eb54c6739 100644 --- a/src/share/classes/java/lang/String.java +++ b/src/share/classes/java/lang/String.java @@ -1492,7 +1492,7 @@ public final class String */ public int hashCode() { int h = hash; - if (h == 0) { + if (h == 0 && count > 0) { int off = offset; char val[] = value; int len = count; diff --git a/src/share/classes/java/security/IdentityScope.java b/src/share/classes/java/security/IdentityScope.java index 0ebc396fa78a578f6efa43f986f5ffa123561ca7..7ed921568952a47a23d595799f7c3a988786b0bc 100644 --- a/src/share/classes/java/security/IdentityScope.java +++ b/src/share/classes/java/security/IdentityScope.java @@ -129,7 +129,8 @@ class IdentityScope extends Identity { /** * Returns the system's identity scope. * - * @return the system's identity scope. + * @return the system's identity scope, or {@code null} if none has been + * set. * * @see #setSystemScope */ diff --git a/src/share/classes/java/util/Collection.java b/src/share/classes/java/util/Collection.java index e7cb3c91e0c8cff27e84dae7224afa5a271c122f..c79e0cde3093509c57be26b49893a3a096c70368 100644 --- a/src/share/classes/java/util/Collection.java +++ b/src/share/classes/java/util/Collection.java @@ -103,6 +103,8 @@ package java.util; * * Java Collections Framework. * + * @param the type of elements in this collection + * * @author Josh Bloch * @author Neal Gafter * @see Set diff --git a/src/share/classes/java/util/DualPivotQuicksort.java b/src/share/classes/java/util/DualPivotQuicksort.java index 07cda259dd49bbeb6e84f9ec58301694987d965e..eedb2389134a39fd8fe575846379d0131dee8670 100644 --- a/src/share/classes/java/util/DualPivotQuicksort.java +++ b/src/share/classes/java/util/DualPivotQuicksort.java @@ -253,7 +253,7 @@ final class DualPivotQuicksort { a[less] = ak; } less++; - } else { // (a[k] > pivot1) - Move a[k] to right part + } else { // (a[k] > pivot1) - Move a[k] to right part /* * We know that pivot1 == a[e3] == pivot2. Thus, we know * that great will still be >= k when the following loop @@ -531,7 +531,7 @@ final class DualPivotQuicksort { a[less] = ak; } less++; - } else { // (a[k] > pivot1) - Move a[k] to right part + } else { // (a[k] > pivot1) - Move a[k] to right part /* * We know that pivot1 == a[e3] == pivot2. Thus, we know * that great will still be >= k when the following loop @@ -826,7 +826,7 @@ final class DualPivotQuicksort { a[less] = ak; } less++; - } else { // (a[k] > pivot1) - Move a[k] to right part + } else { // (a[k] > pivot1) - Move a[k] to right part /* * We know that pivot1 == a[e3] == pivot2. Thus, we know * that great will still be >= k when the following loop @@ -1119,7 +1119,7 @@ final class DualPivotQuicksort { a[less] = ak; } less++; - } else { // (a[k] > pivot1) - Move a[k] to right part + } else { // (a[k] > pivot1) - Move a[k] to right part /* * We know that pivot1 == a[e3] == pivot2. Thus, we know * that great will still be >= k when the following loop @@ -1414,7 +1414,7 @@ final class DualPivotQuicksort { a[less] = ak; } less++; - } else { // (a[k] > pivot1) - Move a[k] to right part + } else { // (a[k] > pivot1) - Move a[k] to right part /* * We know that pivot1 == a[e3] == pivot2. Thus, we know * that great will still be >= k when the following loop @@ -1531,7 +1531,7 @@ final class DualPivotQuicksort { * Sorts the specified range of the array into ascending order. The range * to be sorted extends from the index {@code fromIndex}, inclusive, to * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex}, - * the range to be sorted is empty and the call is a no-op). + * the range to be sorted is empty and the call is a no-op). * *

The {@code <} relation does not provide a total order on all float * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN} @@ -1787,7 +1787,7 @@ final class DualPivotQuicksort { a[less] = ak; } less++; - } else { // (a[k] > pivot1) - Move a[k] to right part + } else { // (a[k] > pivot1) - Move a[k] to right part /* * We know that pivot1 == a[e3] == pivot2. Thus, we know * that great will still be >= k when the following loop @@ -2160,7 +2160,7 @@ final class DualPivotQuicksort { a[less] = ak; } less++; - } else { // (a[k] > pivot1) - Move a[k] to right part + } else { // (a[k] > pivot1) - Move a[k] to right part /* * We know that pivot1 == a[e3] == pivot2. Thus, we know * that great will still be >= k when the following loop diff --git a/src/share/classes/java/util/Iterator.java b/src/share/classes/java/util/Iterator.java index 16b9c431506642cde168f309ea651c37ccdf85da..fd9725de850a6b07f65ec07b360971385c83a883 100644 --- a/src/share/classes/java/util/Iterator.java +++ b/src/share/classes/java/util/Iterator.java @@ -41,6 +41,8 @@ package java.util; * * Java Collections Framework. * + * @param the type of elements returned by this iterator + * * @author Josh Bloch * @see Collection * @see ListIterator diff --git a/src/share/classes/java/util/List.java b/src/share/classes/java/util/List.java index 4ce27c82289f7739c07be470d6bcf2c3ec9aa961..a05fe305681ad0b695041f7fa15eab8ad1fa5941 100644 --- a/src/share/classes/java/util/List.java +++ b/src/share/classes/java/util/List.java @@ -89,6 +89,8 @@ package java.util; * * Java Collections Framework. * + * @param the type of elements in this list + * * @author Josh Bloch * @author Neal Gafter * @see Collection diff --git a/src/share/classes/sun/nio/fs/AbstractWatchKey.java b/src/share/classes/sun/nio/fs/AbstractWatchKey.java index b00c71d37cd30d77eaba42e464afd18d3bdff43e..9faf78cec8275cc9209d5db24e4f596de0dbc494 100644 --- a/src/share/classes/sun/nio/fs/AbstractWatchKey.java +++ b/src/share/classes/sun/nio/fs/AbstractWatchKey.java @@ -59,10 +59,15 @@ abstract class AbstractWatchKey extends WatchKey { // pending events private List> events; + // maps a context to the last event for the context (iff the last queued + // event for the context is an ENTRY_MODIFY event). + private Map> lastModifyEvents; + protected AbstractWatchKey(AbstractWatchService watcher) { this.watcher = watcher; this.state = State.READY; this.events = new ArrayList>(); + this.lastModifyEvents = new HashMap>(); } final AbstractWatchService watcher() { @@ -86,6 +91,7 @@ abstract class AbstractWatchKey extends WatchKey { */ @SuppressWarnings("unchecked") final void signalEvent(WatchEvent.Kind kind, Object context) { + boolean isModify = (kind == StandardWatchEventKind.ENTRY_MODIFY); synchronized (this) { int size = events.size(); if (size > 0) { @@ -100,17 +106,43 @@ abstract class AbstractWatchKey extends WatchKey { return; } + // if this is a modify event and the last entry for the context + // is a modify event then we simply increment the count + if (!lastModifyEvents.isEmpty()) { + if (isModify) { + WatchEvent ev = lastModifyEvents.get(context); + if (ev != null) { + assert ev.kind() == StandardWatchEventKind.ENTRY_MODIFY; + ((Event)ev).increment(); + return; + } + } else { + // not a modify event so remove from the map as the + // last event will no longer be a modify event. + lastModifyEvents.remove(context); + } + } + // if the list has reached the limit then drop pending events // and queue an OVERFLOW event if (size >= MAX_EVENT_LIST_SIZE) { - events.clear(); kind = StandardWatchEventKind.OVERFLOW; + isModify = false; context = null; } } // non-repeated event - events.add(new Event((WatchEvent.Kind)kind, context)); + Event ev = + new Event((WatchEvent.Kind)kind, context); + if (isModify) { + lastModifyEvents.put(context, ev); + } else if (kind == StandardWatchEventKind.OVERFLOW) { + // drop all pending events + events.clear(); + lastModifyEvents.clear(); + } + events.add(ev); signal(); } } @@ -120,6 +152,7 @@ abstract class AbstractWatchKey extends WatchKey { synchronized (this) { List> result = events; events = new ArrayList>(); + lastModifyEvents.clear(); return result; } } diff --git a/src/share/classes/sun/security/krb5/internal/crypto/EType.java b/src/share/classes/sun/security/krb5/internal/crypto/EType.java index b7da802af13ca828079cb471eb04dc8f15fe618f..63d14cf69a2aecd1f80930fb061095f1d60883bf 100644 --- a/src/share/classes/sun/security/krb5/internal/crypto/EType.java +++ b/src/share/classes/sun/security/krb5/internal/crypto/EType.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2000-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,9 +36,9 @@ import sun.security.krb5.Config; import sun.security.krb5.EncryptedData; import sun.security.krb5.EncryptionKey; import sun.security.krb5.KrbException; -import sun.security.krb5.Asn1Exception; import sun.security.krb5.KrbCryptoException; import javax.crypto.*; +import java.util.Arrays; import java.util.List; import java.util.ArrayList; @@ -48,6 +48,23 @@ import java.util.ArrayList; public abstract class EType { private static final boolean DEBUG = Krb5.DEBUG; + private static final boolean ALLOW_WEAK_CRYPTO; + + static { + boolean allowed = true; + try { + Config cfg = Config.getInstance(); + String temp = cfg.getDefault("allow_weak_crypto", "libdefaults"); + if (temp != null && temp.equals("false")) allowed = false; + } catch (Exception exc) { + if (DEBUG) { + System.out.println ("Exception in getting allow_weak_crypto, " + + "using default value " + + exc.getMessage()); + } + } + ALLOW_WEAK_CRYPTO = allowed; + } public static EType getInstance (int eTypeConst) throws KdcErrException { @@ -163,6 +180,10 @@ public abstract class EType { return result; } + // Note: the first 2 entries of BUILTIN_ETYPES and BUILTIN_ETYPES_NOAES256 + // should be kept DES-related. They will be removed when allow_weak_crypto + // is set to false. + private static final int[] BUILTIN_ETYPES = new int[] { EncryptedData.ETYPE_DES_CBC_MD5, EncryptedData.ETYPE_DES_CBC_CRC, @@ -189,10 +210,17 @@ public abstract class EType { } catch (Exception e) { // should not happen } + int[] result; if (allowed < 256) { - return BUILTIN_ETYPES_NOAES256; + result = BUILTIN_ETYPES_NOAES256; + } else { + result = BUILTIN_ETYPES; } - return BUILTIN_ETYPES; + if (!ALLOW_WEAK_CRYPTO) { + // The first 2 etypes are now weak ones + return Arrays.copyOfRange(result, 2, result.length); + } + return result; } /** @@ -207,9 +235,7 @@ public abstract class EType { if (DEBUG) { System.out.println("Exception while getting " + configName + exc.getMessage()); - System.out.println("Using defaults " + - "des-cbc-md5, des-cbc-crc, des3-cbc-sha1," + - " aes128cts, aes256cts, rc4-hmac"); + System.out.println("Using default builtin etypes"); } return getBuiltInDefaults(); } diff --git a/src/share/classes/sun/security/provider/JavaKeyStore.java b/src/share/classes/sun/security/provider/JavaKeyStore.java index 70de46e6160627b92952744fb60dd3baa01282a4..072336e71649e4d57baab9b49bb6ff7f8483f4e0 100644 --- a/src/share/classes/sun/security/provider/JavaKeyStore.java +++ b/src/share/classes/sun/security/provider/JavaKeyStore.java @@ -29,9 +29,9 @@ import java.io.*; import java.security.*; import java.security.cert.Certificate; import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; import java.security.cert.CertificateException; import java.util.*; +import sun.misc.IOUtils; import sun.security.pkcs.EncryptedPrivateKeyInfo; @@ -677,50 +677,39 @@ abstract class JavaKeyStore extends KeyStoreSpi { entry.date = new Date(dis.readLong()); // Read the private key - try { - entry.protectedPrivKey = new byte[dis.readInt()]; - } catch (OutOfMemoryError e) { - throw new IOException("Keysize too big"); - } - dis.readFully(entry.protectedPrivKey); + entry.protectedPrivKey = + IOUtils.readFully(dis, dis.readInt(), true); // Read the certificate chain int numOfCerts = dis.readInt(); - try { - if (numOfCerts > 0) { - entry.chain = new Certificate[numOfCerts]; - } - } catch (OutOfMemoryError e) { - throw new IOException - ("Too many certificates in chain"); - } - for (int j = 0; j < numOfCerts; j++) { - if (xVersion == 2) { - // read the certificate type, and instantiate a - // certificate factory of that type (reuse - // existing factory if possible) - String certType = dis.readUTF(); - if (cfs.containsKey(certType)) { - // reuse certificate factory - cf = cfs.get(certType); - } else { - // create new certificate factory - cf = CertificateFactory.getInstance(certType); - // store the certificate factory so we can - // reuse it later - cfs.put(certType, cf); + if (numOfCerts > 0) { + List certs = new ArrayList<>( + numOfCerts > 10 ? 10 : numOfCerts); + for (int j = 0; j < numOfCerts; j++) { + if (xVersion == 2) { + // read the certificate type, and instantiate a + // certificate factory of that type (reuse + // existing factory if possible) + String certType = dis.readUTF(); + if (cfs.containsKey(certType)) { + // reuse certificate factory + cf = cfs.get(certType); + } else { + // create new certificate factory + cf = CertificateFactory.getInstance(certType); + // store the certificate factory so we can + // reuse it later + cfs.put(certType, cf); + } } + // instantiate the certificate + encoded = IOUtils.readFully(dis, dis.readInt(), true); + bais = new ByteArrayInputStream(encoded); + certs.add(cf.generateCertificate(bais)); + bais.close(); } - // instantiate the certificate - try { - encoded = new byte[dis.readInt()]; - } catch (OutOfMemoryError e) { - throw new IOException("Certificate too big"); - } - dis.readFully(encoded); - bais = new ByteArrayInputStream(encoded); - entry.chain[j] = cf.generateCertificate(bais); - bais.close(); + // We can be sure now that numOfCerts of certs are read + entry.chain = certs.toArray(new Certificate[numOfCerts]); } // Add the entry to the list @@ -753,12 +742,7 @@ abstract class JavaKeyStore extends KeyStoreSpi { cfs.put(certType, cf); } } - try { - encoded = new byte[dis.readInt()]; - } catch (OutOfMemoryError e) { - throw new IOException("Certificate too big"); - } - dis.readFully(encoded); + encoded = IOUtils.readFully(dis, dis.readInt(), true); bais = new ByteArrayInputStream(encoded); entry.cert = cf.generateCertificate(bais); bais.close(); diff --git a/src/share/classes/sun/security/tools/TimestampedSigner.java b/src/share/classes/sun/security/tools/TimestampedSigner.java index efdc3c0c83b8b845bd975a03e6dc9816e3a47db3..549ed8ea21004a8073b2992e0dc96f9983948ae3 100644 --- a/src/share/classes/sun/security/tools/TimestampedSigner.java +++ b/src/share/classes/sun/security/tools/TimestampedSigner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2007-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -375,7 +375,8 @@ public final class TimestampedSigner extends ContentSigner { } if (!isSigner) { keyPurposes = cert.getExtendedKeyUsage(); - if (! keyPurposes.contains(KP_TIMESTAMPING_OID)) { + if (keyPurposes == null || + ! keyPurposes.contains(KP_TIMESTAMPING_OID)) { throw new CertificateException( "Certificate is not valid for timestamping"); } diff --git a/src/share/lib/security/java.security b/src/share/lib/security/java.security index 7d386b715ae0616d9567612a4b3337acee1c256e..1c9404f60af4caea46f99a296adcc054ac61bd4a 100644 --- a/src/share/lib/security/java.security +++ b/src/share/lib/security/java.security @@ -117,11 +117,6 @@ policy.ignoreIdentityScope=false # keystore.type=jks -# -# Class to instantiate as the system scope: -# -system.scope=sun.security.provider.IdentityDatabase - # # List of comma-separated packages that start with or equal this string # will cause a security exception to be thrown when diff --git a/src/solaris/classes/sun/nio/fs/UnixPath.java b/src/solaris/classes/sun/nio/fs/UnixPath.java index 2741915e55de28253e03fabd54154346261f838b..389034da19745300c392aa202b9b2e4c0e7bbd41 100644 --- a/src/solaris/classes/sun/nio/fs/UnixPath.java +++ b/src/solaris/classes/sun/nio/fs/UnixPath.java @@ -624,8 +624,11 @@ class UnixPath public boolean endsWith(Path other) { UnixPath that = checkPath(other); + int thisLen = path.length; + int thatLen = that.path.length; + // other path is longer - if (that.path.length > path.length) + if (thatLen > thisLen) return false; // other path is absolute so this path must be absolute @@ -643,10 +646,10 @@ class UnixPath if (thatOffsetCount == thisOffsetCount) { if (thisOffsetCount == 0) return true; - int expectedLen = path.length; + int expectedLen = thisLen; if (this.isAbsolute() && !that.isAbsolute()) expectedLen--; - if (that.path.length != expectedLen) + if (thatLen != expectedLen) return false; } else { // this path has more elements so given path must be relative @@ -658,7 +661,9 @@ class UnixPath // compare bytes int thisPos = offsets[thisOffsetCount - thatOffsetCount]; int thatPos = that.offsets[0]; - while (thatPos < that.path.length) { + if ((thatLen - thatPos) != (thisLen - thisPos)) + return false; + while (thatPos < thatLen) { if (this.path[thisPos++] != that.path[thatPos++]) return false; } diff --git a/src/solaris/native/java/io/UnixFileSystem_md.c b/src/solaris/native/java/io/UnixFileSystem_md.c index 175c5f35bf22ebe886bf19999cf5ce758f412850..df8240fbfbc2aa271b8a7d2b87ab1a6f7ce1e28d 100644 --- a/src/solaris/native/java/io/UnixFileSystem_md.c +++ b/src/solaris/native/java/io/UnixFileSystem_md.c @@ -414,9 +414,9 @@ Java_java_io_UnixFileSystem_getSpace(JNIEnv *env, jobject this, jlong rv = 0L; WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { - struct statvfs fsstat; - memset(&fsstat, 0, sizeof(struct statvfs)); - if (statvfs(path, &fsstat) == 0) { + struct statvfs64 fsstat; + memset(&fsstat, 0, sizeof(fsstat)); + if (statvfs64(path, &fsstat) == 0) { switch(t) { case java_io_FileSystem_SPACE_TOTAL: rv = jlong_mul(long_to_jlong(fsstat.f_frsize), diff --git a/test/Makefile b/test/Makefile index bffa3ad7cb06a346d9e7354502bef3c81ca862e0..bb5a34fde0ab9bd224c80265f7b677ac72ab5a68 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,5 +1,5 @@ # -# Copyright 1995-2009 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 1995-2010 Sun Microsystems, Inc. All Rights Reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -37,25 +37,19 @@ GET= AWK = awk CAT = cat CD = cd -CHMOD = chmod CP = cp CUT = cut ECHO = echo EGREP = egrep EXPAND = expand -EXPR = expr -KILL = /usr/bin/kill MKDIR = mkdir -NOHUP = nohup PWD = pwd SED = sed -SLEEP = sleep SORT = sort TEE = tee UNAME = uname UNIQ = uniq WC = wc -XHOST = xhost ZIP = zip # Get OS name from uname @@ -211,66 +205,6 @@ ifdef JPRT_ARCHIVE_BUNDLE ARCHIVE_BUNDLE = $(JPRT_ARCHIVE_BUNDLE) endif -# DISPLAY settings for virtual frame buffer -START_XVFB = start-Xvfb.sh -NOHUP_OUTPUT = $(ABS_TEST_OUTPUT_DIR)/start-Xvfb.nohup-output.txt -DISPLAY_PID_FILE=$(ABS_TEST_OUTPUT_DIR)/xvfb-display-number.txt -DISPLAY_SLEEP_TIME=10 -DISPLAY_MAX_SLEEPS=10 -ifeq ($(OS_NAME),solaris) - VIRTUAL_FRAME_BUFFER = true -endif -ifeq ($(OS_NAME),linux) - VIRTUAL_FRAME_BUFFER = true -endif - -# Does not work yet, display dies as soon as it gets used. :^( -VIRTUAL_FRAME_BUFFER = false - -# Are we using a VIRTUAL_FRAME_BUFFER (Xvfb) -ifeq ($(VIRTUAL_FRAME_BUFFER),true) - - PREP_DISPLAY = \ - $(CP) $(START_XVFB) $(ABS_TEST_OUTPUT_DIR); \ - $(CHMOD) a+x $(ABS_TEST_OUTPUT_DIR)/$(START_XVFB); \ - ( $(CD) $(ABS_TEST_OUTPUT_DIR) && \ - $(NOHUP) $(ABS_TEST_OUTPUT_DIR)/$(START_XVFB) $(DISPLAY_PID_FILE) > $(NOHUP_OUTPUT) 2>&1 && \ - $(SLEEP) $(DISPLAY_SLEEP_TIME) ) & \ - count=1; \ - while [ ! -s $(DISPLAY_PID_FILE) ] ; do \ - $(ECHO) "Sleeping $(DISPLAY_SLEEP_TIME) more seconds, DISPLAY not ready"; \ - $(SLEEP) $(DISPLAY_SLEEP_TIME); \ - count=`$(EXPR) $${count} '+' 1`; \ - if [ $${count} -gt $(DISPLAY_MAX_SLEEPS) ] ; then \ - $(ECHO) "ERROR: DISPLAY not ready, giving up on DISPLAY"; \ - exit 9; \ - fi; \ - done ; \ - DISPLAY=":`$(CAT) $(DISPLAY_PID_FILE)`"; \ - export DISPLAY; \ - $(CAT) $(NOHUP_OUTPUT); \ - $(ECHO) "Prepared DISPLAY=$${DISPLAY}"; \ - $(XHOST) || \ - ( $(ECHO) "ERROR: No display" ; exit 8) - - KILL_DISPLAY = \ - ( \ - DISPLAY=":`$(CAT) $(DISPLAY_PID_FILE)`"; \ - export DISPLAY; \ - if [ -s "$(DISPLAY_PID_FILE)" ] ; then \ - $(KILL) `$(CAT) $(DISPLAY_PID_FILE)` > /dev/null 2>&1; \ - $(KILL) -9 `$(CAT) $(DISPLAY_PID_FILE)` > /dev/null 2>&1; \ - fi; \ - $(ECHO) "Killed DISPLAY=$${DISPLAY}"; \ - ) - -else - - PREP_DISPLAY = $(ECHO) "VIRTUAL_FRAME_BUFFER=$(VIRTUAL_FRAME_BUFFER)" - KILL_DISPLAY = $(ECHO) "VIRTUAL_FRAME_BUFFER=$(VIRTUAL_FRAME_BUFFER)" - -endif - # How to create the test bundle (pass or fail, we want to create this) # Follow command with ";$(BUNDLE_UP_AND_EXIT)", so it always gets executed. ZIP_UP_RESULTS = ( $(MKDIR) -p `dirname $(ARCHIVE_BUNDLE)` \ @@ -327,7 +261,7 @@ BUNDLE_UP_AND_EXIT = \ $(ECHO) "Missing file: $${_summary}" >> $(STATS_TXT); \ fi; \ $(CAT) $(STATS_TXT); \ - $(ZIP_UP_RESULTS) && $(KILL_DISPLAY) ; \ + $(ZIP_UP_RESULTS) ; \ $(TESTEXIT) \ ) @@ -629,7 +563,6 @@ jtreg_tests: prep $(PRODUCT_HOME) $(JTREG) $(EXCLUDELIST) ( \ ( JT_HOME=$(shell $(GETMIXEDPATH) "$(JT_HOME)"); \ export JT_HOME; \ - $(PREP_DISPLAY) && \ $(shell $(GETMIXEDPATH) "$(JTREG)") \ $(JTREG_BASIC_OPTIONS) \ -r:$(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)")/JTreport \ diff --git a/test/ProblemList.txt b/test/ProblemList.txt index ddcd68d3624a45343373a3a57bf6aa12516c638a..8b3f03d837e3b366657f5d99226b29978993592f 100644 --- a/test/ProblemList.txt +++ b/test/ProblemList.txt @@ -1,6 +1,6 @@ ########################################################################### # -# Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2009-2010 Sun Microsystems, Inc. All Rights Reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -431,6 +431,12 @@ java/lang/ClassLoader/deadlock/TestCrossDelegate.sh generic-all # jdk_management +# Fails on linux: KO: StringMonitor notification missed or not emitted +javax/management/monitor/NonComparableAttributeValueTest.java generic-all + +# Port conflict? Fails with communication error +sun/management/jmxremote/bootstrap/PasswordFilePermissionTest.sh generic-all + # Fails on Windows 2000, Test failed for iiop java.lang.NullPointerException # at org.omg.stub.javax.management.remote.rmi._RMIConnectionImpl_Tie._invoke(Unknown Source) # at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:653) @@ -583,6 +589,9 @@ javax/print/attribute/MediaMappingsTest.java generic-all # Suspect many of these tests auffer from using fixed ports, no concrete # evidence. +# Times out on Windows X64 +sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java generic-all + # Dies on Solaris 10 sparc and sparcv9, Linux -ea -esa with # Interrupted or IO exception, maybe writing to non-unique named file? com/sun/net/httpserver/bugs/B6373555.java generic-all @@ -736,6 +745,13 @@ java/net/ProxySelector/B6737819.java generic-all # Suspect many of these tests auffer from using fixed ports, no concrete # evidence. +# Occasionally Failing with java.lang.AssertionError on Windows X64 +# at sun.nio.ch.PendingIoCache.clearPendingIoMap(PendingIoCache.java:144) +#java/nio/channels/FileChannel/ReleaseOnCloseDeadlock.java windows-all + +# Some kind of sleep/wake problem on Windows X64 +java/nio/channels/Selector/Wakeup.java windows-all + # Fails with -ea -esa, Assertion error, but only on Solaris 10 machines? com/sun/nio/sctp/SctpChannel/Send.java generic-all com/sun/nio/sctp/SctpChannel/Shutdown.java generic-all @@ -932,6 +948,18 @@ java/rmi/server/UnicastRemoteObject/unexportObject/UnexportLeak.java generic-all # jdk_security +# Unknown problem, could be a jtreg -samevm issue? +# Error while cleaning up threads after test +java/security/Security/SynchronizedAccess.java generic-all + +# Failing on Solaris X64 (-d64 -server) with: +# GSSException: Failure unspecified at GSS-API level +# (Mechanism level: Specified version of key is not available (44)) +sun/security/krb5/auto/BasicKrb5Test.java generic-all + +# Solaris X86 failures, readjar.jks: No such file or directory +sun/security/tools/keytool/readjar.sh generic-all + # Fails with -ea -esa, but only on Solaris sparc? Suspect it is timing out sun/security/tools/keytool/standard.sh generic-all @@ -1256,6 +1284,13 @@ tools/jar/index/MetaInf.java windows-all # jdk_util +# Fails with assertion error on windows +# 11 separate stacktraces created... file reuse problem? +java/util/zip/ZipFile/ReadLongZipFileName.java generic-all + +# Recent failure on all platforms +sun/util/resources/TimeZone/Bug6317929.java generic-all + # Fails with -ea -esa on all platforms with Assertion error java/util/ResourceBundle/Test4300693.java generic-all diff --git a/test/com/sun/jndi/ldap/InvalidLdapFilters.java b/test/com/sun/jndi/ldap/InvalidLdapFilters.java new file mode 100644 index 0000000000000000000000000000000000000000..023841f8e96c87311820193b0629729a2fc0f4ab --- /dev/null +++ b/test/com/sun/jndi/ldap/InvalidLdapFilters.java @@ -0,0 +1,311 @@ +/* + * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6916202 + * @summary More cases of invalid ldap filters accepted and processed + * @run main/othervm InvalidLdapFilters valid (cn=Babs) + * @run main/othervm InvalidLdapFilters valid (&(cn=Bob)) + * @run main/othervm InvalidLdapFilters valid (&(objectClass=*)(uid=*)) + * @run main/othervm InvalidLdapFilters valid (|(cn=Bob)) + * @run main/othervm InvalidLdapFilters valid (|(objectClass=*)(uid=*)) + * @run main/othervm InvalidLdapFilters valid (!(cn=Tim)) + * @run main/othervm InvalidLdapFilters valid (!(!(cn=Tim))) + * @run main/othervm InvalidLdapFilters valid (!(&(objectClass=*)(uid=*))) + * @run main/othervm InvalidLdapFilters valid (!(|(objectClass=*)(uid=*))) + * @run main/othervm InvalidLdapFilters valid (o=univ*of*mich*) + * @run main/othervm InvalidLdapFilters valid (seeAlso=) + * @run main/othervm InvalidLdapFilters valid (cn:caseExactMatch:=Flintstone) + * @run main/othervm InvalidLdapFilters valid (cn:=Betty) + * @run main/othervm InvalidLdapFilters valid (sn:dn:2.4.6.8.10:=Barney) + * @run main/othervm InvalidLdapFilters valid (o:dn:=Ace) + * @run main/othervm InvalidLdapFilters valid (:1.2.3:=Wilma) + * @run main/othervm InvalidLdapFilters valid (:DN:2.4.6.8.10:=Dino) + * @run main/othervm InvalidLdapFilters valid (1.2.3=abc) + * @run main/othervm InvalidLdapFilters valid (cn;lang-de;lang-en=abc) + * @run main/othervm InvalidLdapFilters valid (owner=abc) + * @run main/othervm InvalidLdapFilters valid (sn;lang-en:dn:2.4.6.8.10:=Barney) + * @run main/othervm InvalidLdapFilters valid + (&(objectClass=Person)(|(sn=Jensen)(cn=Bab*))) + * @run main/othervm InvalidLdapFilters invalid "(&(cn=Robert Dean)))" + * @run main/othervm InvalidLdapFilters invalid (&|(cn=Bob)) + * @run main/othervm InvalidLdapFilters invalid (&&(cn=Bob)) + * @run main/othervm InvalidLdapFilters invalid (|&(cn=Bob)) + * @run main/othervm InvalidLdapFilters invalid (||(cn=Bob)) + * @run main/othervm InvalidLdapFilters invalid (:1.2.:=Wilma) + * @run main/othervm InvalidLdapFilters invalid (::DN:2.4.6.8.10:=Dino) + * @run main/othervm InvalidLdapFilters invalid (:DN::2.4.6.8.10:=Dino) + * @run main/othervm InvalidLdapFilters invalid (:DN:2.4.6.8.10::=Dino) + * @run main/othervm InvalidLdapFilters invalid (:DN:2.4.6..8.10:=Dino) + * @run main/othervm InvalidLdapFilters invalid (:DN:2.4.6.8.:=Dino) + * @run main/othervm InvalidLdapFilters invalid (1.2.;::=abc) + * @run main/othervm InvalidLdapFilters invalid (1.2.3;::=abc) + * @run main/othervm InvalidLdapFilters invalid (1.2.3;x;=abc) + * @run main/othervm InvalidLdapFilters invalid (1.2.3:x::=abc) + * @run main/othervm InvalidLdapFilters invalid (1.2.3:x=abc) + * @run main/othervm InvalidLdapFilters invalid (sn;:dn:2.4.6.8.10:=Barney) + * @run main/othervm InvalidLdapFilters invalid "\"((objectClass=*)&(uid=*))\"" + * @run main/othervm InvalidLdapFilters invalid "&(objectClass=*)(uid=*)" + * @run main/othervm InvalidLdapFilters invalid "(:DN:2.4.6.8.10:cn:=Dino)" + * @run main/othervm InvalidLdapFilters invalid "(:DN:2.4.6.8.10:cn=Dino)" + * @run main/othervm InvalidLdapFilters invalid + "((objectCategory=person)(cn=u)(!(cn=u2*)))" + * @run main/othervm InvalidLdapFilters invalid + "((&(objectClass=user)(cn=andy*)(cn=steve*)(cn=bob*)))" + * + * @author Xuelei Fan + */ + +import java.io.*; +import javax.naming.*; +import javax.naming.directory.*; +import java.util.Properties; +import java.util.Hashtable; + +import java.net.Socket; +import java.net.ServerSocket; + +public class InvalidLdapFilters { + // Should we run the client or server in a separate thread? + // + // Both sides can throw exceptions, but do you have a preference + // as to which side should be the main thread. + static boolean separateServerThread = true; + + // use any free port by default + volatile int serverPort = 0; + + // Is the server ready to serve? + volatile static boolean serverReady = false; + + // Define the server side of the test. + // + // If the server prematurely exits, serverReady will be set to true + // to avoid infinite hangs. + void doServerSide() throws Exception { + ServerSocket serverSock = new ServerSocket(serverPort); + + // signal client, it's ready to accecpt connection + serverPort = serverSock.getLocalPort(); + serverReady = true; + + // accept a connection + Socket socket = serverSock.accept(); + System.out.println("Server: Connection accepted"); + + InputStream is = socket.getInputStream(); + OutputStream os = socket.getOutputStream(); + + // read the bindRequest + while (is.read() != -1) { + // ignore + is.skip(is.available()); + break; + } + + byte[] bindResponse = {0x30, 0x0C, 0x02, 0x01, 0x01, 0x61, 0x07, 0x0A, + 0x01, 0x00, 0x04, 0x00, 0x04, 0x00}; + // write bindResponse + os.write(bindResponse); + os.flush(); + + // ignore any more request. + while (is.read() != -1) { + // ignore + is.skip(is.available()); + } + + is.close(); + os.close(); + socket.close(); + serverSock.close(); + } + + // Define the client side of the test. + // + // If the server prematurely exits, serverReady will be set to true + // to avoid infinite hangs. + void doClientSide() throws Exception { + // Wait for server to get started. + while (!serverReady) { + Thread.sleep(50); + } + + // set up the environment for creating the initial context + Hashtable env = new Hashtable(); + env.put(Context.INITIAL_CONTEXT_FACTORY, + "com.sun.jndi.ldap.LdapCtxFactory"); + env.put(Context.PROVIDER_URL, "ldap://localhost:" + serverPort); + env.put("com.sun.jndi.ldap.read.timeout", "1000"); + + // env.put(Context.SECURITY_AUTHENTICATION, "simple"); + // env.put(Context.SECURITY_PRINCIPAL,"cn=root"); + // env.put(Context.SECURITY_CREDENTIALS,"root"); + + // create initial context + DirContext context = new InitialDirContext(env); + + // searching + SearchControls scs = new SearchControls(); + scs.setSearchScope(SearchControls.SUBTREE_SCOPE); + + try { + NamingEnumeration answer = + context.search("o=sun,c=us", searchFilter, scs); + } catch (InvalidSearchFilterException isfe) { + if (filterIsValid) { + // unexpected filter exception. + throw new Exception("Unexpected ISFE", isfe); + } else { + // ignore, it is the expected filter exception. + System.out.println("Expected exception: " + isfe.getMessage()); + } + } catch (NamingException ne) { + // maybe a read timeout exception, as the server does not response. + if (filterIsValid) { + System.out.println("Expected exception: " + ne.getMessage()); + } else { + throw new Exception("Not an InvalidSearchFilterException", ne); + } + } + + context.close(); + } + + private static boolean filterIsValid; + private static String searchFilter; + + private static void parseArguments(String[] args) { + System.out.println("arguments length: " + args.length); + if (args[0].equals("valid")) { + filterIsValid = true; + } + + searchFilter = args[1]; + } + + /* + * ============================================================ + * The remainder is just support stuff + */ + + // client and server thread + Thread clientThread = null; + Thread serverThread = null; + + // client and server exceptions + volatile Exception serverException = null; + volatile Exception clientException = null; + + void startServer(boolean newThread) throws Exception { + if (newThread) { + serverThread = new Thread() { + public void run() { + try { + doServerSide(); + } catch (Exception e) { + /* + * Our server thread just died. + * + * Release the client, if not active already... + */ + System.err.println("Server died..."); + System.err.println(e); + serverReady = true; + serverException = e; + } + } + }; + serverThread.start(); + } else { + doServerSide(); + } + } + + void startClient(boolean newThread) throws Exception { + if (newThread) { + clientThread = new Thread() { + public void run() { + try { + doClientSide(); + } catch (Exception e) { + /* + * Our client thread just died. + */ + System.err.println("Client died..."); + clientException = e; + } + } + }; + clientThread.start(); + } else { + doClientSide(); + } + } + + // Primary constructor, used to drive remainder of the test. + InvalidLdapFilters() throws Exception { + if (separateServerThread) { + startServer(true); + startClient(false); + } else { + startClient(true); + startServer(false); + } + + /* + * Wait for other side to close down. + */ + if (separateServerThread) { + serverThread.join(); + } else { + clientThread.join(); + } + + /* + * When we get here, the test is pretty much over. + * + * If the main thread excepted, that propagates back + * immediately. If the other thread threw an exception, we + * should report back. + */ + if (serverException != null) { + System.out.print("Server Exception:"); + throw serverException; + } + if (clientException != null) { + System.out.print("Client Exception:"); + throw clientException; + } + } + + public static void main(String[] args) throws Exception { + // parse the customized arguments + parseArguments(args); + + // start the test + new InvalidLdapFilters(); + } + +} diff --git a/test/java/nio/file/Files/PrintFileTree.java b/test/java/nio/file/Files/PrintFileTree.java index dc2c49f8db105fa234582e38126ecaae9012a580..40d2ab52b141017fbcf7eeb88f7c527ff0614d74 100644 --- a/test/java/nio/file/Files/PrintFileTree.java +++ b/test/java/nio/file/Files/PrintFileTree.java @@ -28,27 +28,33 @@ import java.util.*; /** * Invokes Files.walkFileTree to traverse a file tree and prints - * each of the directories and files. The -L option causes symbolic - * links to be followed. + * each of the directories and files. The -follow option causes symbolic + * links to be followed and the -printCycles option will print links + * where the target of the link is an ancestor directory. */ public class PrintFileTree { public static void main(String[] args) throws Exception { boolean followLinks = false; - Path dir; - - if (args[0].equals("-L")) { - followLinks = true; - dir = Paths.get(args[1]); - } else { - dir = Paths.get(args[0]); + boolean printCycles = false; + int i = 0; + while (i < (args.length-1)) { + switch (args[i]) { + case "-follow" : followLinks = true; break; + case "-printCycles" : printCycles = true; break; + default: + throw new RuntimeException(args[i] + " not recognized"); + } + i++; } + Path dir = Paths.get(args[i]); Set options = new HashSet(); if (followLinks) options.add(FileVisitOption.FOLLOW_LINKS); + final boolean reportCycles = printCycles; Files.walkFileTree(dir, options, Integer.MAX_VALUE, new FileVisitor() { public FileVisitResult preVisitDirectory(FileRef dir) { System.out.println(dir); @@ -59,7 +65,8 @@ public class PrintFileTree { return FileVisitResult.CONTINUE; } public FileVisitResult visitFile(FileRef file, BasicFileAttributes attrs) { - System.out.println(file); + if (!attrs.isDirectory() || reportCycles) + System.out.println(file); return FileVisitResult.CONTINUE; } public FileVisitResult postVisitDirectory(FileRef dir, IOException exc) { diff --git a/test/java/nio/file/Files/walk_file_tree.sh b/test/java/nio/file/Files/walk_file_tree.sh index 897625d46ac765cb5da4be4c02397e15015915f4..b5a173c53920afb377fa1f8d55310f131e5224d4 100644 --- a/test/java/nio/file/Files/walk_file_tree.sh +++ b/test/java/nio/file/Files/walk_file_tree.sh @@ -61,12 +61,20 @@ find "$ROOT" > out2 diff out1 out2 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi -# repeat test following links (use -follow instead of -L -# to allow running on older systems) -$JAVA PrintFileTree -L "$ROOT" > out1 -find "$ROOT" -follow > out2 +# repeat test following links. Some versions of find(1) output +# cycles (sym links to ancestor directories), other versions do +# not. For that reason we run PrintFileTree with the -printCycles +# option when the output without this option differs to find(1). +find "$ROOT" -follow > out1 +$JAVA PrintFileTree -follow "$ROOT" > out2 diff out1 out2 -if [ $? != 0 ]; then failures=`expr $failures + 1`; fi +if [ $? != 0 ]; + then + # re-run printing cycles to stdout + $JAVA PrintFileTree -follow -printCycles "$ROOT" > out2 + diff out1 out2 + if [ $? != 0 ]; then failures=`expr $failures + 1`; fi + fi # test SKIP_SIBLINGS $JAVA SkipSiblings "$ROOT" diff --git a/test/java/nio/file/Path/CheckPermissions.java b/test/java/nio/file/Path/CheckPermissions.java index 9e0f796afc75455b875f9904c2d26d7e4f251a26..97763de9574fb477ca427da7860c567d38025a97 100644 --- a/test/java/nio/file/Path/CheckPermissions.java +++ b/test/java/nio/file/Path/CheckPermissions.java @@ -197,7 +197,7 @@ public class CheckPermissions { } public static void main(String[] args) throws IOException { - Path dir = Paths.get(System.getProperty("test.src", ".")); + Path dir = Paths.get(System.getProperty("test.dir", ".")); Path file = dir.resolve("file1234").createFile(); try { LoggingSecurityManager.install(); diff --git a/test/java/nio/file/Path/PathOps.java b/test/java/nio/file/Path/PathOps.java index 6482d5e88b239f3b3d9918c95d654c3db404217e..3517baacc16455328ea35cef3f5fa7bcad6e7380 100644 --- a/test/java/nio/file/Path/PathOps.java +++ b/test/java/nio/file/Path/PathOps.java @@ -22,7 +22,7 @@ */ /* @test - * @bug 4313887 6838333 + * @bug 4313887 6838333 6925932 * @summary Unit test for java.nio.file.Path path operations */ @@ -614,17 +614,34 @@ public class PathOps { test("/foo") .ends("foo") .ends("/foo") - .notEnds("/"); + .notEnds("fool"); test("/foo/bar") .ends("bar") .ends("foo/bar") .ends("/foo/bar") - .notEnds("/bar"); + .notEnds("ar") + .notEnds("barack") + .notEnds("/bar") + .notEnds("o/bar"); test("foo") - .ends("foo"); + .ends("foo") + .notEnds("oo") + .notEnds("oola"); test("foo/bar") .ends("bar") - .ends("foo/bar"); + .ends("foo/bar") + .notEnds("r") + .notEnds("barmaid") + .notEnds("/bar"); + test("foo/bar/gus") + .ends("gus") + .ends("bar/gus") + .ends("foo/bar/gus") + .notEnds("g") + .notEnds("/gus") + .notEnds("r/gus") + .notEnds("barack/gus") + .notEnds("bar/gust"); // elements test("a/b/c") diff --git a/test/java/nio/file/WatchService/LotsOfEvents.java b/test/java/nio/file/WatchService/LotsOfEvents.java new file mode 100644 index 0000000000000000000000000000000000000000..24770918afe0bdbfe29395fce7c7049399d777c8 --- /dev/null +++ b/test/java/nio/file/WatchService/LotsOfEvents.java @@ -0,0 +1,222 @@ +/* + * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* @test + * @bug 6907760 6929532 + * @summary Tests WatchService behavior when lots of events are pending + * @library .. + * @run main/timeout=180 LotsOfEvents + */ + +import java.nio.file.*; +import static java.nio.file.StandardWatchEventKind.*; +import java.io.IOException; +import java.io.OutputStream; +import java.util.*; +import java.util.concurrent.TimeUnit; + +public class LotsOfEvents { + + static final Random rand = new Random(); + + public static void main(String[] args) throws Exception { + Path dir = TestUtil.createTemporaryDirectory(); + try { + testOverflowEvent(dir); + testModifyEventsQueuing(dir); + } finally { + TestUtil.removeAll(dir); + } + } + + /** + * Tests that OVERFLOW events are not retreived with other events. + */ + static void testOverflowEvent(Path dir) + throws IOException, InterruptedException + { + WatchService watcher = dir.getFileSystem().newWatchService(); + try { + dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE); + + // create a lot of files + int n = 1024; + Path[] files = new Path[n]; + for (int i=0; i expectedKind, + int count) + throws IOException, InterruptedException + { + // wait for key to be signalled - the timeout is long to allow for + // polling implementations + WatchKey key = watcher.poll(15, TimeUnit.SECONDS); + if (key != null && count == 0) + throw new RuntimeException("Key was signalled (unexpected)"); + if (key == null && count > 0) + throw new RuntimeException("Key not signalled (unexpected)"); + + int nread = 0; + boolean gotOverflow = false; + while (key != null) { + List> events = key.pollEvents(); + for (WatchEvent event: events) { + WatchEvent.Kind kind = event.kind(); + if (kind == expectedKind) { + // expected event kind + if (++nread > count) + throw new RuntimeException("More events than expected!!"); + } else if (kind == OVERFLOW) { + // overflow event should not be retrieved with other events + if (events.size() > 1) + throw new RuntimeException("Overflow retrieved with other events"); + gotOverflow = true; + } else { + throw new RuntimeException("Unexpected event '" + kind + "'"); + } + } + if (!key.reset()) + throw new RuntimeException("Key is no longer valid"); + key = watcher.poll(2, TimeUnit.SECONDS); + } + + // check that all expected events were received or there was an overflow + if (nread < count && !gotOverflow) + throw new RuntimeException("Insufficient events"); + } + + /** + * Tests that check that ENTRY_MODIFY events are queued efficiently + */ + static void testModifyEventsQueuing(Path dir) + throws IOException, InterruptedException + { + // this test uses a random number of files + final int nfiles = 5 + rand.nextInt(10); + DirectoryEntry[] entries = new DirectoryEntry[nfiles]; + for (int i=0; i modified = new HashSet(); + for (WatchEvent event: key.pollEvents()) { + WatchEvent.Kind kind = event.kind(); + Path file = (kind == OVERFLOW) ? null : (Path)event.context(); + if (kind == ENTRY_MODIFY) { + boolean added = modified.add(file); + if (!added) { + throw new RuntimeException( + "ENTRY_MODIFY events not queued efficiently"); + } + } else { + if (file != null) modified.remove(file); + } + } + if (!key.reset()) + throw new RuntimeException("Key is no longer valid"); + key = watcher.poll(2, TimeUnit.SECONDS); + } + } + + } finally { + watcher.close(); + } + } + + static class DirectoryEntry { + private final Path file; + DirectoryEntry(Path file) { + this.file = file; + } + void create() throws IOException { + if (file.notExists()) + file.createFile(); + + } + void deleteIfExists() throws IOException { + file.deleteIfExists(); + } + void modifyIfExists() throws IOException { + if (file.exists()) { + OutputStream out = file.newOutputStream(StandardOpenOption.APPEND); + try { + out.write("message".getBytes()); + } finally { + out.close(); + } + } + } + } + +} diff --git a/test/java/nio/file/WatchService/OverflowEventIsLoner.java b/test/java/nio/file/WatchService/OverflowEventIsLoner.java deleted file mode 100644 index 0b48a942d844b7d90b1c1bfd48bf1e2e12bb9c35..0000000000000000000000000000000000000000 --- a/test/java/nio/file/WatchService/OverflowEventIsLoner.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -/* @test - * @bug 6907760 - * @summary Check that the OVERFLOW event is not retrieved with other events - * @library .. - */ - -import java.nio.file.*; -import static java.nio.file.StandardWatchEventKind.*; -import java.io.IOException; -import java.util.List; -import java.util.concurrent.TimeUnit; - -public class OverflowEventIsLoner { - - static void drainEvents(WatchService watcher, - WatchEvent.Kind expectedKind, - int count) - throws IOException, InterruptedException - { - // wait for key to be signalled - the timeout is long to allow for - // polling implementations - WatchKey key = watcher.poll(15, TimeUnit.SECONDS); - if (key != null && count == 0) - throw new RuntimeException("Key was signalled (unexpected)"); - if (key == null && count > 0) - throw new RuntimeException("Key not signalled (unexpected)"); - - int nread = 0; - boolean gotOverflow = false; - do { - List> events = key.pollEvents(); - for (WatchEvent event: events) { - WatchEvent.Kind kind = event.kind(); - if (kind == expectedKind) { - // expected event kind - if (++nread > count) - throw new RuntimeException("More events than expected!!"); - } else if (kind == OVERFLOW) { - // overflow event should not be retrieved with other events - if (events.size() > 1) - throw new RuntimeException("Overflow retrieved with other events"); - gotOverflow = true; - } else { - throw new RuntimeException("Unexpected event '" + kind + "'"); - } - } - if (!key.reset()) - throw new RuntimeException("Key is no longer valid"); - key = watcher.poll(2, TimeUnit.SECONDS); - } while (key != null); - - // check that all expected events were received or there was an overflow - if (nread < count && !gotOverflow) - throw new RuntimeException("Insufficient events"); - } - - - static void test(Path dir) throws IOException, InterruptedException { - WatchService watcher = dir.getFileSystem().newWatchService(); - try { - WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE); - - // create a lot of files - int n = 1024; - Path[] files = new Path[n]; - for (int i=0; i