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,64 @@
/*
* Copyright (c) 2001, 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.
*/
// Skeleton class generated by rmic, do not edit.
// Contents subject to change without notice.
public final class Impl1_Skel
implements java.rmi.server.Skeleton
{
private static final java.rmi.server.Operation[] operations = {
new java.rmi.server.Operation("void pong()")
};
private static final long interfaceHash = -6081108852319377105L;
public java.rmi.server.Operation[] getOperations() {
return (java.rmi.server.Operation[]) operations.clone();
}
public void dispatch(java.rmi.Remote obj, java.rmi.server.RemoteCall call, int opnum, long hash)
throws java.lang.Exception
{
if (hash != interfaceHash)
throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch");
Impl1 server = (Impl1) obj;
switch (opnum) {
case 0: // pong()
{
call.releaseInputStream();
server.pong();
try {
call.getResultStream(true);
} catch (java.io.IOException e) {
throw new java.rmi.MarshalException("error marshalling return", e);
}
break;
}
default:
throw new java.rmi.UnmarshalException("invalid method number");
}
}
}

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 2001, 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.
*/
// Stub class generated by rmic, do not edit.
// Contents subject to change without notice.
public final class Impl1_Stub
extends java.rmi.server.RemoteStub
implements Pong
{
private static final java.rmi.server.Operation[] operations = {
new java.rmi.server.Operation("void pong()")
};
private static final long interfaceHash = -6081108852319377105L;
// constructors
public Impl1_Stub() {
super();
}
public Impl1_Stub(java.rmi.server.RemoteRef ref) {
super(ref);
}
// methods from remote interfaces
// implementation of pong()
public void pong()
throws PongException, java.rmi.RemoteException
{
try {
java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 0, interfaceHash);
ref.invoke(call);
ref.done(call);
} catch (java.lang.RuntimeException e) {
throw e;
} catch (java.rmi.RemoteException e) {
throw e;
} catch (PongException e) {
throw e;
} catch (java.lang.Exception e) {
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
}
}
}

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2001, 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.
*/
// Stub class generated by rmic, do not edit.
// Contents subject to change without notice.
public final class Impl2_Stub
extends java.rmi.server.RemoteStub
implements Pong
{
private static final long serialVersionUID = 2;
private static java.lang.reflect.Method $method_pong_0;
static {
try {
$method_pong_0 = Pong.class.getMethod("pong", new java.lang.Class[] {});
} catch (java.lang.NoSuchMethodException e) {
throw new java.lang.NoSuchMethodError(
"stub class initialization failed");
}
}
// constructors
public Impl2_Stub(java.rmi.server.RemoteRef ref) {
super(ref);
}
// methods from remote interfaces
// implementation of pong()
public void pong()
throws PongException, java.rmi.RemoteException
{
try {
ref.invoke(this, $method_pong_0, null, -5941237182396893426L);
} catch (java.lang.RuntimeException e) {
throw e;
} catch (java.rmi.RemoteException e) {
throw e;
} catch (PongException e) {
throw e;
} catch (java.lang.Exception e) {
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
}
}
}

View file

@ -0,0 +1,123 @@
/*
* Copyright (c) 2001, 2012, 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 4010355
* @summary When an exception is thrown by a remote method invocation, the
* stack trace of the exception catchable by the client application should
* comprise both the client-side trace as well as the server-side trace, as
* serialized with the Throwable from the server.
* @author Peter Jones
*
* @build ServerStackTrace ServerStackTrace_Stub
* @run main/othervm ServerStackTrace
*/
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
interface Ping extends Remote {
void ping() throws PingException, RemoteException;
}
class PingException extends Exception {
}
public class ServerStackTrace implements Ping {
public void ping() throws PingException {
__BAR__();
}
private void __BAR__() throws PingException {
throw new PingException();
}
private static void __FOO__(Ping stub)
throws PingException, RemoteException
{
stub.ping();
}
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for RFE 4010355\n");
ServerStackTrace impl = new ServerStackTrace();
try {
Ping stub = (Ping) UnicastRemoteObject.exportObject(impl);
StackTraceElement[] remoteTrace;
try {
__FOO__(stub);
throw new RuntimeException("TEST FAILED: no exception caught");
} catch (PingException e) {
System.err.println(
"trace of exception thrown by remote call:");
e.printStackTrace();
System.err.println();
remoteTrace = e.getStackTrace();
}
int fooIndex = -1;
int barIndex = -1;
for (int i = 0; i < remoteTrace.length; i++) {
StackTraceElement e = remoteTrace[i];
if (e.getMethodName().equals("__FOO__")) {
if (fooIndex != -1) {
throw new RuntimeException("TEST FAILED: " +
"trace contains more than one __FOO__");
}
fooIndex = i;
} else if (e.getMethodName().equals("__BAR__")) {
if (barIndex != -1) {
throw new RuntimeException("TEST FAILED: " +
"trace contains more than one __BAR__");
}
barIndex = i;
}
}
if (fooIndex == -1) {
throw new RuntimeException(
"TEST FAILED: trace lacks client-side method __FOO__");
}
if (barIndex == -1) {
throw new RuntimeException(
"TEST FAILED: trace lacks server-side method __BAR__");
}
if (fooIndex < barIndex) {
throw new RuntimeException(
"TEST FAILED: trace contains client-side method __FOO__ " +
"before server-side method __BAR__");
}
System.err.println("TEST PASSED");
} finally {
try {
UnicastRemoteObject.unexportObject(impl, true);
} catch (Exception e) {
}
}
}
}

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2001, 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.
*/
// Stub class generated by rmic, do not edit.
// Contents subject to change without notice.
public final class ServerStackTrace_Stub
extends java.rmi.server.RemoteStub
implements Ping
{
private static final long serialVersionUID = 2;
private static java.lang.reflect.Method $method_ping_0;
static {
try {
$method_ping_0 = Ping.class.getMethod("ping", new java.lang.Class[] {});
} catch (java.lang.NoSuchMethodException e) {
throw new java.lang.NoSuchMethodError(
"stub class initialization failed");
}
}
// constructors
public ServerStackTrace_Stub(java.rmi.server.RemoteRef ref) {
super(ref);
}
// methods from remote interfaces
// implementation of ping()
public void ping()
throws PingException, java.rmi.RemoteException
{
try {
ref.invoke(this, $method_ping_0, null, 5866401369815527589L);
} catch (java.lang.RuntimeException e) {
throw e;
} catch (java.rmi.RemoteException e) {
throw e;
} catch (PingException e) {
throw e;
} catch (java.lang.Exception e) {
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
}
}
}

View file

@ -0,0 +1,158 @@
/*
* Copyright (c) 2001, 2012, 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 4487532
* @summary When the system property "sun.rmi.server.suppressStackTraces" is
* set to boolean true, then the RMI runtime should take positive action to
* counteract the new feature in 1.4 of an exception's stack trace being part
* of its serialized form so that the server-side stack trace of an exception
* that occurs during the execution of a remote method invocation gets
* marshalled to the client. In most cases, this feature-- along with the
* final fix to 4010355 to make the server-side stack trace data available
* at the RMI client application level-- is highly desirable, but this system
* property provides an opportunity to suppress the server-side stack trace
* data of exceptions thrown by remote methods from being marshalled, perhaps
* for reasons of performance or confidentiality requirements.
* @author Peter Jones
*
* @build SuppressStackTraces Impl2_Stub Impl1_Stub Impl1_Skel
* @run main/othervm SuppressStackTraces
*/
import java.io.IOException;
import java.io.ObjectInputStream;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Arrays;
interface Pong extends Remote {
void pong() throws PongException, RemoteException;
}
class PongException extends Exception {
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
in.defaultReadObject();
/*
* Verify right at unmarshalling time that this exception instance
* contains no stack trace data from the server (regardless of whether
* or not it would be apparent at the RMI client application level).
*/
StackTraceElement[] trace = getStackTrace();
if (trace.length > 0) {
throw new RuntimeException(
"TEST FAILED: exception contained non-empty stack trace: " +
Arrays.asList(trace));
}
}
}
// stub class generated with "rmic -v1.2 ..."
class Impl2 implements Pong {
public void pong() throws PongException { __BAR__(); }
public void __BAR__() throws PongException { throw new PongException(); }
}
// stub and skeleton classes generated with "rmic -v1.1 ..."
class Impl1 implements Pong {
public void pong() throws PongException { __BAR__(); }
public void __BAR__() throws PongException { throw new PongException(); }
}
public class SuppressStackTraces {
private static void __FOO__(Pong stub)
throws PongException, RemoteException
{
stub.pong();
}
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for RFE 4487532\n");
System.setProperty("sun.rmi.server.suppressStackTraces", "true");
Remote impl2 = new Impl2();
Remote impl1 = new Impl1();
try {
/*
* Verify behavior for both -v1.1 and -v1.2 stub protocols.
*/
verifySuppression((Pong) UnicastRemoteObject.exportObject(impl2));
verifySuppression((Pong) UnicastRemoteObject.exportObject(impl1));
System.err.println(
"TEST PASSED (server-side stack trace data suppressed)");
} finally {
try {
UnicastRemoteObject.unexportObject(impl1, true);
} catch (Exception e) {
}
try {
UnicastRemoteObject.unexportObject(impl2, true);
} catch (Exception e) {
}
}
}
private static void verifySuppression(Pong stub) throws Exception {
System.err.println("testing stub for exported object: " + stub);
StackTraceElement[] remoteTrace;
try {
__FOO__(stub);
throw new RuntimeException("TEST FAILED: no exception caught");
} catch (PongException e) {
System.err.println(
"trace of exception thrown by remote call:");
e.printStackTrace();
System.err.println();
remoteTrace = e.getStackTrace();
}
int fooIndex = -1;
for (int i = 0; i < remoteTrace.length; i++) {
StackTraceElement e = remoteTrace[i];
if (e.getMethodName().equals("__FOO__")) {
if (fooIndex != -1) {
throw new RuntimeException(
"TEST FAILED: trace contains more than one __FOO__");
}
fooIndex = i;
} else if (e.getMethodName().equals("__BAR__")) {
throw new RuntimeException(
"TEST FAILED: trace contains __BAR__");
}
}
if (fooIndex == -1) {
throw new RuntimeException(
"TEST FAILED: trace lacks client-side method __FOO__");
}
}
}