undefect. CWE-407 — 63 sites patched across 27 ecosystems

Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
This commit is contained in:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,125 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8056179
* @summary Unit test for BasicPermissionCollection subclass
*/
import java.security.BasicPermission;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.SecurityPermission;
import java.util.Enumeration;
public class BasicPermissionCollection {
public static void main(String[] args) throws Exception {
int testFail = 0;
TestPermission perm = new TestPermission("foo");
PermissionCollection perms = perm.newPermissionCollection();
// test 1
System.out.println("test 1: add throws IllegalArgumentExc");
try {
perms.add(new SecurityPermission("createAccessControlContext"));
System.err.println("Expected IllegalArgumentException");
testFail++;
} catch (IllegalArgumentException iae) {}
// test 2
System.out.println("test 2: implies returns false for wrong class");
if (perms.implies(new SecurityPermission("getPolicy"))) {
System.err.println("Expected false, returned true");
testFail++;
}
// test 3
System.out.println("test 3: implies returns true for match on name");
perms.add(new TestPermission("foo"));
if (!perms.implies(new TestPermission("foo"))) {
System.err.println("Expected true, returned false");
testFail++;
}
// test 4
System.out.println("test 4: implies returns true for wildcard match");
perms.add(new TestPermission("bar.*"));
if (!perms.implies(new TestPermission("bar.foo"))) {
System.err.println("Expected true, returned false");
testFail++;
}
// test 5
System.out.println
("test 5: implies returns false for invalid wildcard");
perms.add(new TestPermission("baz*"));
if (perms.implies(new TestPermission("baz.foo"))) {
System.err.println("Expected false, returned true");
testFail++;
}
// test 6
System.out.println
("test 6: implies returns true for deep wildcard match");
if (!perms.implies(new TestPermission("bar.foo.baz"))) {
System.err.println("Expected true, returned false");
testFail++;
}
// test 7
System.out.println
("test 7: implies returns true for all wildcard match");
perms.add(new TestPermission("*"));
if (!perms.implies(new TestPermission("yes"))) {
System.err.println("Expected true, returned false");
testFail++;
}
// test 8
System.out.println("test 8: elements returns correct number of perms");
int numPerms = 0;
Enumeration<Permission> e = perms.elements();
while (e.hasMoreElements()) {
numPerms++;
System.out.println(e.nextElement());
}
if (numPerms != 4) {
System.err.println("Expected 4, got " + numPerms);
testFail++;
}
if (testFail > 0) {
throw new Exception(testFail + " test(s) failed");
}
}
private static class TestPermission extends BasicPermission {
TestPermission(String name) {
super(name);
}
}
}

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4157921
* @summary Test subclasses of BasicPermission to make sure different
* subclasses don't equal or imply each other.
*/
import java.security.Permission;
import java.security.BasicPermission;
class A extends BasicPermission {
public A(String name) { super(name); }
}
class B extends BasicPermission {
public B(String name) { super(name); }
}
public class EqualsImplies {
public static void main(String[]args) throws Exception {
Permission p1 = new A("foo");
Permission p2 = new B("foo");
if (p1.implies(p2) || p2.implies(p1) || p1.equals(p2)) {
throw new Exception("Test failed");
}
// make sure permissions imply and equal themselves
if (! (p1.implies(p1) && p1.equals(p1))) {
throw new Exception("Test failed");
}
}
}

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6569218
* @summary Specification of some BasicPermission method does not fit with implementation
*/
import java.security.BasicPermission;
public class ExitVMEquals {
public static void main(String[] args) throws Exception {
BasicPermission bp1 = new BP("exitVM");
BasicPermission bp2 = new BP("exitVM.*");
StringBuffer sb = new StringBuffer();
// First, make sure the old restrictions on exitVM and exitVM.* still hold.
if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");
// Test against hashCode spec
if (bp1.hashCode() != bp1.getName().hashCode())
sb.append("bp1 hashCode not spec consistent\n");
if (bp2.hashCode() != bp2.getName().hashCode())
sb.append("bp2 hashCode not spec consistent\n");
// Test against equals spec
if (bp1.getName().equals(bp2.getName())) {
if (!bp1.equals(bp2)) {
sb.append("BP breaks equals spec\n");
}
}
if (!bp1.getName().equals(bp2.getName())) {
if (bp1.equals(bp2)) {
sb.append("BP breaks equals spec in another way\n");
}
}
// Tests against common knowledge: If equals, then hashCode should be same
if (bp1.equals(bp2)) {
if (bp1.hashCode() != bp2.hashCode()) {
sb.append("Equal objects have unequal hashCode?\n");
}
}
if (sb.length() > 0) {
throw new Exception(sb.toString());
}
}
}
class BP extends BasicPermission {
BP(String name) {
super(name);
}
}

View file

@ -0,0 +1,70 @@
/*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4291610
* @summary BasicPermission.newPermissionCollection collection does not
* enforce homogeneity
*/
import java.security.BasicPermission;
public class Homogeneity {
public static void main(String[] args) {
java.lang.RuntimePermission rp = new java.lang.RuntimePermission
("*");
java.lang.RuntimePermission rp2 = new java.lang.RuntimePermission
("exitVM");
java.net.NetPermission np = new java.net.NetPermission
("setDefaultAuthenticator");
// should be able to add identical BasicPermission subclasses to the
// same collection
java.security.PermissionCollection perms = rp.newPermissionCollection();
try {
perms.add(rp);
perms.add(rp2);
} catch (IllegalArgumentException iae) {
throw new SecurityException("GOOD ADD TEST FAILED");
}
// make sure you can't add different BasicPermission subclasses
// to the same collection
try {
// this should fail
perms.add(np);
throw new SecurityException("BAD ADD TEST FAILED");
} catch (IllegalArgumentException iae) {
// good
}
// make sure a BasicPermissionCollection doesn't imply
// random BasicPermission subclasses
if (perms.implies(np)) {
throw new SecurityException("IMPLIES TEST FAILED");
}
}
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6568872
* @summary BasicPermission.newPermissionCollection() violates general contract specified in Permission class
*/
public class MixedBasicPermissions {
public static void main(String[] args) {
try {
new java.net.NetPermission("1.1.1.1", "connect").newPermissionCollection().add(new java.util.PropertyPermission("j", "read"));
} catch (Exception e) {
return;
// Correct place
}
throw new RuntimeException("Should not be here");
}
}

View file

@ -0,0 +1,108 @@
/*
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4240252
* @summary Make sure BasicPermission constructor raises
* NullPointerException if permission name is null, and
* IllegalArgumentException is permission name is empty.
* @run main/othervm NullOrEmptyName
*/
import java.util.PropertyPermission;
public class NullOrEmptyName {
public static void main(String[]args) throws Exception {
NullOrEmptyName noe = new NullOrEmptyName();
noe.run();
try {
new PropertyPermission(null, "read");
throw new Exception("Expected NullPointerException not thrown");
} catch (NullPointerException npe) {
// expected exception thrown
}
try {
new PropertyPermission("", "read");
throw new Exception("Expected IllegalArgumentException not " +
"thrown");
} catch (IllegalArgumentException iae) {
// expected exception thrown
}
}
void run() throws Exception {
try {
System.getProperty(null);
throw new Exception("Expected NullPointerException not " +
"thrown");
} catch (NullPointerException npe) {
// expected exception thrown
}
try {
System.getProperty(null, "value");
throw new Exception("Expected NullPointerException not " +
"thrown");
} catch (NullPointerException npe) {
// expected exception thrown
}
try {
System.getProperty("");
throw new Exception("Expected IllegalArgumentException not " +
"thrown");
} catch (IllegalArgumentException iae) {
// expected exception thrown
}
try {
System.getProperty("", "value");
throw new Exception("Expected IllegalArgumentException not " +
"thrown");
} catch (IllegalArgumentException iae) {
// expected exception thrown
}
try {
System.setProperty(null, "value");
throw new Exception("Expected NullPointerException not " +
"thrown");
} catch (NullPointerException npe) {
// expected exception thrown
}
try {
System.setProperty("", "value");
throw new Exception("Expected IllegalArgumentException not " +
"thrown");
} catch (IllegalArgumentException iae) {
// expected exception thrown
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,126 @@
/*
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4511601 7054918
* @summary BasicPermissionCollection does not set permClass
* during deserialization
*/
import java.security.*;
import java.io.*;
public class PermClass {
public static void main(String[] args) throws Exception {
String dir = System.getProperty("test.src");
if (dir == null) {
dir = ".";
}
MyPermission mp = new MyPermission("PermClass");
if (args != null && args.length == 1 && args[0] != null) {
// set up serialized file (arg is JDK version)
PermissionCollection bpc = mp.newPermissionCollection();
bpc.add(mp);
File sFile = new File(dir, "PermClass." + args[0]);
ObjectOutputStream oos = new ObjectOutputStream
(new FileOutputStream("PermClass." + args[0]));
oos.writeObject(bpc);
oos.close();
System.exit(0);
}
// read in a 1.2.1 BasicPermissionCollection
File sFile = new File(dir, "PermClass.1.2.1");
try (FileInputStream fis = new FileInputStream(sFile);
ObjectInputStream ois = new ObjectInputStream(fis)) {
PermissionCollection pc = (PermissionCollection)ois.readObject();
System.out.println("1.2.1 collection = " + pc);
if (pc.implies(mp)) {
System.out.println("JDK 1.2.1 test passed");
} else {
throw new Exception("JDK 1.2.1 test failed");
}
}
// read in a 1.3.1 BasicPermissionCollection
sFile = new File(dir, "PermClass.1.3.1");
try (FileInputStream fis = new FileInputStream(sFile);
ObjectInputStream ois = new ObjectInputStream(fis)) {
PermissionCollection pc = (PermissionCollection)ois.readObject();
System.out.println("1.3.1 collection = " + pc);
if (pc.implies(mp)) {
System.out.println("JDK 1.3.1 test passed");
} else {
throw new Exception("JDK 1.3.1 test failed");
}
}
// read in a 1.4 BasicPermissionCollection
sFile = new File(dir, "PermClass.1.4");
try (FileInputStream fis = new FileInputStream(sFile);
ObjectInputStream ois = new ObjectInputStream(fis)) {
PermissionCollection pc = (PermissionCollection)ois.readObject();
System.out.println("1.4 collection = " + pc);
if (pc.implies(mp)) {
System.out.println("JDK 1.4 test 1 passed");
} else {
throw new Exception("JDK 1.4 test 1 failed");
}
}
// write out current BasicPermissionCollection
PermissionCollection bpc = mp.newPermissionCollection();
bpc.add(mp);
sFile = new File(dir, "PermClass.current");
try (FileOutputStream fos = new FileOutputStream("PermClass.current");
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
oos.writeObject(bpc);
}
// read in current BasicPermissionCollection
try (FileInputStream fis = new FileInputStream("PermClass.current");
ObjectInputStream ois = new ObjectInputStream(fis)) {
PermissionCollection pc = (PermissionCollection)ois.readObject();
System.out.println("current collection = " + pc);
if (pc.implies(mp)) {
System.out.println("JDK 1.4 test 2 passed");
} else {
throw new Exception("JDK 1.4 test 2 failed");
}
}
}
}
class MyPermission extends BasicPermission {
public MyPermission(String name) {
super(name);
}
}

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4502729 7054918
* @summary BasicPermissionCollection serial version UID incorrect
*/
import java.security.*;
import java.io.*;
public class SerialVersion {
public static void main(String[] args) throws Exception {
String dir = System.getProperty("test.src");
File sFile = new File (dir,"SerialVersion.1.2.1");
// read in a 1.2.1 BasicPermissionCollection
try (FileInputStream fis = new FileInputStream(sFile);
ObjectInputStream ois = new ObjectInputStream(fis)) {
PermissionCollection pc = (PermissionCollection)ois.readObject();
System.out.println("1.2.1 collection = " + pc);
}
// read in a 1.3.1 BasicPermissionCollection
sFile = new File (dir,"SerialVersion.1.3.1");
try (FileInputStream fis = new FileInputStream(sFile);
ObjectInputStream ois = new ObjectInputStream(fis)) {
PermissionCollection pc = (PermissionCollection)ois.readObject();
System.out.println("1.3.1 collection = " + pc);
}
// read in a 1.4 BasicPermissionCollection
sFile = new File (dir,"SerialVersion.1.4");
try (FileInputStream fis = new FileInputStream(sFile);
ObjectInputStream ois = new ObjectInputStream(fis)) {
PermissionCollection pc = (PermissionCollection)ois.readObject();
System.out.println("1.4 collection = " + pc);
}
// write out current BasicPermissionCollection
MyPermission mp = new MyPermission("SerialVersionTest");
PermissionCollection bpc = mp.newPermissionCollection();
sFile = new File (dir,"SerialVersion.current");
try (FileOutputStream fos = new FileOutputStream("SerialVersion.current");
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
oos.writeObject(bpc);
}
// read in current BasicPermissionCollection
try (FileInputStream fis = new FileInputStream("SerialVersion.current");
ObjectInputStream ois = new ObjectInputStream(fis)) {
PermissionCollection pc = (PermissionCollection)ois.readObject();
System.out.println("current collection = " + pc);
}
}
}
class MyPermission extends BasicPermission {
public MyPermission(String name) {
super(name);
}
}

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.lang.RuntimePermission;
import java.net.NetPermission;
import java.sql.SQLPermission;
import java.util.PropertyPermission;
import javax.net.ssl.SSLPermission;
/*
* @test
* @bug 7167056
* @summary Check that BasicPermission subclasses don't throw exception if name
* contains wildcard character ("*") but does not signify a
* wildcard match
* @modules java.sql
*/
public class Wildcard {
public static void main(String[] args) throws Exception {
wildcard("*java");
wildcard("java*");
wildcard("ja*va");
}
private static void wildcard(String wildcard) throws Exception {
new RuntimePermission(wildcard);
new NetPermission(wildcard);
new SQLPermission(wildcard);
new PropertyPermission(wildcard, "read");
new SSLPermission(wildcard);
}
}