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
66
test/jdk/java/net/PlainSocketImpl/BigBacklog.java
Normal file
66
test/jdk/java/net/PlainSocketImpl/BigBacklog.java
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
* @author Gary Ellison
|
||||
* @bug 4106600
|
||||
* @summary java.net.SocketImpl backlog value bug avoidance
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
public class BigBacklog
|
||||
{
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
ServerSocket soc = null;
|
||||
Socket csoc = null;
|
||||
int port = 0;
|
||||
|
||||
try {
|
||||
soc = new ServerSocket(port, Integer.MAX_VALUE);
|
||||
port = soc.getLocalPort();
|
||||
} catch(Exception e) {
|
||||
System.err.println("Failed. Unexpected exception:" + e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
csoc = new Socket(InetAddress.getLocalHost(), port);
|
||||
} catch(Exception e) {
|
||||
System.err.println("Failed. Unexpected exception:" + e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
soc.close();
|
||||
csoc.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
System.err.println("Passed. OKAY");
|
||||
|
||||
}
|
||||
}
|
||||
107
test/jdk/java/net/PlainSocketImpl/CustomSocketImplFactory.java
Normal file
107
test/jdk/java/net/PlainSocketImpl/CustomSocketImplFactory.java
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2021, 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 8024952
|
||||
* @summary ClassCastException in SocketImpl.accept() when using custom socketImpl
|
||||
* @run main/othervm CustomSocketImplFactory
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
public class CustomSocketImplFactory implements SocketImplFactory {
|
||||
|
||||
@Override
|
||||
public SocketImpl createSocketImpl() {
|
||||
try {
|
||||
SocketImpl s = new CustomSocketImpl();
|
||||
System.out.println("Created " + s);
|
||||
return s;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Socket.setSocketImplFactory(new CustomSocketImplFactory());
|
||||
try (ServerSocket ss = new ServerSocket(0)) {
|
||||
ss.setSoTimeout(1);
|
||||
ss.accept();
|
||||
System.out.println("PASS");
|
||||
} catch (SocketTimeoutException | NullPointerException e) {
|
||||
// Not a real socket impl
|
||||
}
|
||||
}
|
||||
|
||||
class CustomSocketImpl extends SocketImpl {
|
||||
|
||||
public void create(boolean stream) throws IOException {
|
||||
}
|
||||
|
||||
public void connect(String host, int port) throws IOException {
|
||||
}
|
||||
|
||||
public void connect(InetAddress addr, int port) throws IOException {
|
||||
}
|
||||
|
||||
public void connect(SocketAddress addr, int timeout) throws IOException {
|
||||
}
|
||||
|
||||
public void bind(InetAddress host, int port) throws IOException {
|
||||
}
|
||||
|
||||
public void listen(int backlog) throws IOException {
|
||||
}
|
||||
|
||||
public void accept(SocketImpl s) throws IOException {
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
public void sendUrgentData(int data) throws IOException {
|
||||
}
|
||||
|
||||
public Object getOption(int i) throws SocketException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setOption(int i, Object o) throws SocketException {
|
||||
}
|
||||
}
|
||||
}
|
||||
37
test/jdk/java/net/PlainSocketImpl/SetBufferSize.java
Normal file
37
test/jdk/java/net/PlainSocketImpl/SetBufferSize.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 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 4270108
|
||||
* @summary Make sure no exception would be throw by SetReceiveBufferSize.
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
|
||||
public class SetBufferSize {
|
||||
public static void main(String[] args) throws Exception {
|
||||
DatagramSocket soc = new DatagramSocket();
|
||||
soc.setReceiveBufferSize(Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
56
test/jdk/java/net/PlainSocketImpl/SetOption.java
Normal file
56
test/jdk/java/net/PlainSocketImpl/SetOption.java
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2021, 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 4165948
|
||||
* @summary java.net.SocketImpl {set,get}Option throws SocketException
|
||||
* when socket is closed.
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
public class SetOption {
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
|
||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||
ServerSocket ss = new ServerSocket(0, 0, loopback);
|
||||
|
||||
Socket s1 = new Socket(loopback, ss.getLocalPort());
|
||||
Socket s2 = ss.accept();
|
||||
|
||||
s1.close();
|
||||
boolean exc_thrown = false;
|
||||
try {
|
||||
s1.setSoTimeout(1000);
|
||||
} catch (SocketException e) {
|
||||
exc_thrown = true;
|
||||
}
|
||||
|
||||
if (!exc_thrown) {
|
||||
throw new Exception("SocketException not thrown on closed socket");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue