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,50 @@
/*
* Copyright (c) 2009, 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 6669869
* @summary Tests DesignTime property in different application contexts
* @author Sergey Malenkov
*/
import java.beans.Beans;
public class TestDesignTime implements Runnable {
public static void main(String[] args) throws InterruptedException {
if (Beans.isDesignTime()) {
throw new Error("unexpected DesignTime property");
}
Beans.setDesignTime(!Beans.isDesignTime());
ThreadGroup group = new ThreadGroup("$$$");
Thread thread = new Thread(group, new TestDesignTime());
thread.start();
thread.join();
}
public void run() {
if (Beans.isDesignTime()) {
throw new Error("shared DesignTime property");
}
}
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2009, 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 6669869
* @summary Tests GuiAvailable property in different application contexts
* @author Sergey Malenkov
*/
import java.awt.GraphicsEnvironment;
import java.beans.Beans;
public class TestGuiAvailable implements Runnable {
public static void main(String[] args) throws InterruptedException {
if (Beans.isGuiAvailable() == GraphicsEnvironment.isHeadless()) {
throw new Error("unexpected GuiAvailable property");
}
Beans.setGuiAvailable(!Beans.isGuiAvailable());
ThreadGroup group = new ThreadGroup("$$$");
Thread thread = new Thread(group, new TestGuiAvailable());
thread.start();
thread.join();
}
public void run() {
if (Beans.isGuiAvailable() == GraphicsEnvironment.isHeadless()) {
throw new Error("shared GuiAvailable property");
}
}
}

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 1997, 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 4067824
* @summary Tests exception details in Beans.instantiate()
* @author Graham Hamilton
*/
import java.beans.Beans;
import java.io.FileOutputStream;
import java.io.StreamCorruptedException;
public class Test4067824 {
public static void main(String[] args) throws Exception {
ClassLoader cl = Test4067824.class.getClassLoader();
try {
Beans.instantiate(cl, "Test4067824");
}
catch (ClassNotFoundException exception) {
// This is expected. Make sure there is the right detail message:
if (exception.toString().indexOf("IllegalAccessException") < 0)
throw new Error("unexpected exception", exception);
}
FileOutputStream fout = new FileOutputStream("foo.ser");
fout.write(new byte [] {1, 2, 3, 4, 5});
fout.close();
try {
// trying to instantiate corrupt foo.ser
Beans.instantiate(cl, "foo");
throw new Error("Instantiated corrupt .ser file OK!!??");
}
catch (ClassNotFoundException exception) {
// expected exception
}
catch (StreamCorruptedException exception) {
// expected exception
}
}
// private constructor means Beans.instantiate() will fail
private Test4067824() {
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2003, 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 4343723
* @summary Tests nested exception in Beans.instantiate()
* @author Mark Davidson
*/
import java.beans.Beans;
import java.io.IOException;
public class Test4343723 {
public static void main(String[] args) {
try {
// The TestBean class has a protected constructor and will
// throw an exception as a result of Class.newInstance()
Beans.instantiate(Test4343723.class.getClassLoader(), "Test4343723");
}
catch (ClassNotFoundException exception) {
if (null == exception.getCause())
throw new Error("unexpected exception", exception);
}
catch (IOException exception) {
throw new Error("unexpected exception", exception);
}
}
// protected constructor means Beans.instantiate() will fail
protected Test4343723() {
}
}

View file

@ -0,0 +1,87 @@
/*
* Copyright (c) 2018, 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.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
/**
* @test
* @bug 8205454
*/
public final class TypoInBeanDescription {
private static final String[] typos = {"&amp;", "&lt;", "&gt;", "&quot;"};
public static void main(final String[] args) throws IOException {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
Files.walkFileTree(fs.getPath("/modules/java.desktop"), new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) {
file = file.subpath(2, file.getNameCount());
String name = file.toString();
if (name.endsWith(".class")) {
name = name.substring(0, name.indexOf(".")).replace('/', '.');
final Class<?> type;
try {
type = Class.forName(name);
} catch (Throwable e) {
return FileVisitResult.CONTINUE;
}
final BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(type);
} catch (IntrospectionException e) {
return FileVisitResult.CONTINUE;
}
test(beanInfo);
}
return FileVisitResult.CONTINUE;
}
});
}
private static void test(final BeanInfo beanInfo) {
for (var pd : beanInfo.getPropertyDescriptors()) {
String d = pd.getShortDescription();
String n = pd.getName();
String dn = pd.getDisplayName();
for (String typo : typos) {
if (d.contains(typo) || n.contains(typo) || dn.contains(typo)) {
throw new RuntimeException("Wrong name: " + beanInfo.getBeanDescriptor());
}
}
}
}
}