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:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
50
test/jdk/java/beans/Beans/6669869/TestDesignTime.java
Normal file
50
test/jdk/java/beans/Beans/6669869/TestDesignTime.java
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
51
test/jdk/java/beans/Beans/6669869/TestGuiAvailable.java
Normal file
51
test/jdk/java/beans/Beans/6669869/TestGuiAvailable.java
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
65
test/jdk/java/beans/Beans/Test4067824.java
Normal file
65
test/jdk/java/beans/Beans/Test4067824.java
Normal 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() {
|
||||
}
|
||||
}
|
||||
53
test/jdk/java/beans/Beans/Test4343723.java
Normal file
53
test/jdk/java/beans/Beans/Test4343723.java
Normal 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() {
|
||||
}
|
||||
}
|
||||
87
test/jdk/java/beans/Beans/TypoInBeanDescription.java
Normal file
87
test/jdk/java/beans/Beans/TypoInBeanDescription.java
Normal 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 = {"&", "<", ">", """};
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue