Skip to content

Commit c9722c0

Browse files
committed
Fix spotbugs-security warnings
1 parent b2d1357 commit c9722c0

File tree

50 files changed

+123
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+123
-13
lines changed

junixsocket-common/src/main/java/org/newsclub/net/unix/AFServerSocket.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* @author Christian Kohlschütter
4545
*/
4646
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.CouplingBetweenObjects"})
47+
@SuppressFBWarnings("UNENCRYPTED_SERVER_SOCKET")
4748
public abstract class AFServerSocket<A extends AFSocketAddress> extends ServerSocket implements
4849
AFSomeSocketThing {
4950
private final AFSocketImpl<A> implementation;

junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocket.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public abstract class AFSocket<A extends AFSocketAddress> extends Socket impleme
6868
* @param afh The conversion helper to get a socket address from an encoded hostname.
6969
* @throws SocketException on error.
7070
*/
71-
@SuppressFBWarnings("CT_CONSTRUCTOR_THROW")
71+
@SuppressFBWarnings({"CT_CONSTRUCTOR_THROW", "UNENCRYPTED_SOCKET"})
7272
protected AFSocket(final AFSocketImpl<A> impl, AFSocketAddressFromHostname<A> afh)
7373
throws SocketException {
7474
super(impl);

junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocketAddress.java

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ private static void initAFSocketAddress(AFSocketAddress addr, int port,
194194
* @return The new instance.
195195
* @throws SocketException on error.
196196
*/
197+
@SuppressFBWarnings("OBJECT_DESERIALIZATION") // we craft the serialized data
197198
protected static <A extends AFSocketAddress> A newDeserializedAFSocketAddress(int port,
198199
final byte[] socketAddress, Lease<ByteBuffer> nativeAddress, AFAddressFamily<A> af,
199200
AFSocketAddressConstructor<A> constructor) throws SocketException {

junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocketFactory.java

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import javax.net.SocketFactory;
2828

29+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
30+
2931
/**
3032
* The base for a SocketFactory that connects to UNIX sockets.
3133
*
@@ -35,6 +37,7 @@
3537
* @see AFUNIXSocketFactory
3638
* @param <A> The supported address type.
3739
*/
40+
@SuppressFBWarnings("UNENCRYPTED_SOCKET")
3841
public abstract class AFSocketFactory<A extends AFSocketAddress> extends SocketFactory implements
3942
AFSocketAddressFromHostname<A> {
4043

@@ -77,6 +80,7 @@ protected final boolean isInetAddressSupported(InetAddress address) {
7780
protected abstract Socket connectTo(A addr) throws IOException;
7881

7982
@SuppressWarnings("unchecked")
83+
@SuppressFBWarnings("UNENCRYPTED_SOCKET")
8084
private Socket connectTo(SocketAddress addr) throws IOException {
8185
if (AFSocketAddress.canMap(addr, socketAddressClass)) {
8286
return connectTo((A) AFSocketAddress.mapOrFail(addr, socketAddressClass));

junixsocket-common/src/main/java/org/newsclub/net/unix/AFTIPCSocketAddress.java

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.eclipse.jdt.annotation.NonNullByDefault;
4040
import org.newsclub.net.unix.pool.ObjectPool.Lease;
4141

42+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
43+
4244
/**
4345
* An {@link AFSocketAddress} for TIPC sockets.
4446
*
@@ -110,6 +112,7 @@
110112
*
111113
* @author Christian Kohlschütter (documentation credits to Jon Maloy and the TIPC team).
112114
*/
115+
@SuppressFBWarnings("REDOS")
113116
public final class AFTIPCSocketAddress extends AFSocketAddress {
114117
private static final long serialVersionUID = 1L; // do not change!
115118

junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketAddress.java

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.eclipse.jdt.annotation.NonNull;
4040
import org.newsclub.net.unix.pool.ObjectPool.Lease;
4141

42+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
43+
4244
/**
4345
* Describes an {@link InetSocketAddress} that actually uses AF_UNIX sockets instead of AF_INET.
4446
*
@@ -48,6 +50,7 @@
4850
* @author Christian Kohlschütter
4951
*/
5052
@SuppressWarnings("PMD.ShortMethodName")
53+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
5154
public final class AFUNIXSocketAddress extends AFSocketAddress {
5255
private static final long serialVersionUID = 1L; // do not change!
5356

junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketFactory.java

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import javax.net.SocketFactory;
2828

29+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
30+
2931
/**
3032
* The base for a SocketFactory that connects to UNIX sockets.
3133
*
@@ -59,6 +61,7 @@ protected AFUNIXSocket connectTo(AFUNIXSocketAddress addr) throws IOException {
5961
* system property &quot;org.newsclub.net.unix.socket.hostname&quot;), forwarding all other
6062
* requests to the fallback {@link SocketFactory}.
6163
*/
64+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
6265
private abstract static class DefaultSocketHostnameSocketFactory extends AFUNIXSocketFactory {
6366
private static final String PROP_SOCKET_HOSTNAME = "org.newsclub.net.unix.socket.hostname";
6467

@@ -89,6 +92,7 @@ private static String getDefaultSocketHostname() {
8992
* This is particularly useful for JDBC drivers that take a "socketFactory" and a
9093
* "socketFactoryArg". The latter will be passed as a constructor argument.
9194
*/
95+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
9296
public static final class FactoryArg extends DefaultSocketHostnameSocketFactory {
9397
private final File socketFile;
9498

@@ -133,6 +137,7 @@ public AFUNIXSocketAddress addressFromHost(String host, int port) throws SocketE
133137
* NOTE: While it is technically possible, it is highly discouraged to programmatically change the
134138
* value of the property as it can lead to concurrency issues and undefined behavior.
135139
*/
140+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
136141
public static final class SystemProperty extends DefaultSocketHostnameSocketFactory {
137142
private static final String PROP_SOCKET_DEFAULT = "org.newsclub.net.unix.socket.default";
138143

@@ -167,6 +172,7 @@ public AFUNIXSocketAddress addressFromHost(String host, int port) throws SocketE
167172
* encoded and without the closing bracket. Since this is an invalid hostname, it will not trigger
168173
* a DNS lookup, but can still be used within a JDBC Connection URL.
169174
*/
175+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
170176
public static final class URIScheme extends AFUNIXSocketFactory {
171177
private static final String FILE_SCHEME_PREFIX = "file://";
172178
private static final String FILE_SCHEME_PREFIX_ENCODED = "file%";

junixsocket-common/src/main/java/org/newsclub/net/unix/AFVSOCKSocketAddress.java

+3
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@
3535

3636
import org.newsclub.net.unix.pool.ObjectPool.Lease;
3737

38+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
39+
3840
/**
3941
* An {@link AFSocketAddress} for VSOCK sockets.
4042
*
4143
* @author Christian Kohlschütter
4244
*/
45+
@SuppressFBWarnings("REDOS")
4346
public final class AFVSOCKSocketAddress extends AFSocketAddress {
4447
private static final long serialVersionUID = 1L; // do not change!
4548

junixsocket-common/src/main/java/org/newsclub/net/unix/HostAndPort.java

+3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
import java.util.regex.Matcher;
2727
import java.util.regex.Pattern;
2828

29+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
30+
2931
/**
3032
* Hostname and port.
3133
*
3234
* @author Christian Kohlschütter
3335
*/
36+
@SuppressFBWarnings("REDOS")
3437
public final class HostAndPort {
3538
private static final Pattern PAT_HOST_AND_PORT = Pattern.compile(
3639
"^//((?<userinfo>[^/\\@]*)\\@)?(?<host>[^/\\:]+)(?:\\:(?<port>[0-9]+))?");

junixsocket-common/src/main/java/org/newsclub/net/unix/NativeLibraryLoader.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
3737

38-
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
38+
@SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "PATH_TRAVERSAL_IN"})
3939
final class NativeLibraryLoader implements Closeable {
4040
private static final String PROP_LIBRARY_DISABLE = "org.newsclub.net.unix.library.disable";
4141
private static final String PROP_LIBRARY_OVERRIDE = "org.newsclub.net.unix.library.override";
@@ -210,6 +210,7 @@ private void deleteLibTmpDelFiles(File libDir) {
210210

211211
@Override
212212
@SuppressWarnings("PMD.CognitiveComplexity")
213+
@SuppressFBWarnings("URLCONNECTION_SSRF_FD")
213214
synchronized String load() throws IOException, LinkageError {
214215
if (libraryNameAndVersion == null) {
215216
return null;

junixsocket-common/src/main/java/org/newsclub/net/unix/RAFChannelProvider.java

+3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
import java.util.UUID;
2626
import java.util.concurrent.atomic.AtomicBoolean;
2727

28+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
29+
2830
/**
2931
* Hack to get a readable AND writable {@link FileChannel} for a {@link FileDescriptor}.
3032
*
3133
* @author Christian Kohlschütter
3234
*/
35+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
3336
final class RAFChannelProvider extends RandomAccessFile implements FileDescriptorAccess {
3437
private static final File DEV_NULL = new File("/dev/null");
3538

junixsocket-common/src/main/java/org/newsclub/net/unix/SocketAddressUtil.java

+3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323

2424
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
2525

26+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
27+
2628
/**
2729
* {@link SocketAddress}-related helper methods.
2830
*
2931
* @author Christian Kohlschütter
3032
*/
3133
@IgnoreJRERequirement // see src/main/java15
34+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
3235
final class SocketAddressUtil {
3336
private SocketAddressUtil() {
3437
throw new IllegalStateException("No instances");

junixsocket-common/src/test/java/org/newsclub/net/unix/AFUNIXSocketAddressTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
3939
import com.kohlschutter.testutil.AssertUtil;
4040

41-
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
41+
@SuppressFBWarnings({"DMI_HARDCODED_ABSOLUTE_FILENAME", "OBJECT_DESERIALIZATION"})
4242
public class AFUNIXSocketAddressTest {
4343

4444
@Test

junixsocket-common/src/test/java/org/newsclub/net/unix/SocketChannelTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545

4646
import org.junit.jupiter.api.Test;
4747

48+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
4849
import com.kohlschutter.testutil.TestAbortedWithImportantMessageException;
4950
import com.kohlschutter.testutil.TestAbortedWithImportantMessageException.MessageType;
5051
import com.kohlschutter.testutil.TestAsyncUtil;
5152

53+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
5254
public abstract class SocketChannelTest<A extends SocketAddress> extends SocketTestBase<A> {
5355
protected SocketChannelTest(AddressSpecifics<A> asp) {
5456
super(asp);

junixsocket-common/src/test/java/org/newsclub/net/unix/SocketTestBase.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
*/
6666
@SuppressWarnings({"PMD.AbstractClassWithoutAbstractMethod", "PMD.CouplingBetweenObjects"})
6767
@SuppressFBWarnings({
68-
"THROWS_METHOD_THROWS_CLAUSE_THROWABLE", "THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION"})
68+
"THROWS_METHOD_THROWS_CLAUSE_THROWABLE", "THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION",
69+
"PREDICTABLE_RANDOM"})
6970
public abstract class SocketTestBase<A extends SocketAddress> { // NOTE: needs to be public for
7071
// junit
7172

junixsocket-common/src/test/java/org/newsclub/net/unix/java/JavaAddressSpecifics.java

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import org.newsclub.net.unix.CloseablePair;
3636
import org.opentest4j.TestAbortedException;
3737

38+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
39+
40+
@SuppressFBWarnings({"UNENCRYPTED_SERVER_SOCKET", "UNENCRYPTED_SOCKET"})
3841
public final class JavaAddressSpecifics implements AddressSpecifics<InetSocketAddress> {
3942
public static final AddressSpecifics<InetSocketAddress> INSTANCE = new JavaAddressSpecifics();
4043

junixsocket-common/src/test/java/org/newsclub/net/unix/jep380/SocketChannelTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@AFSocketCapabilityRequirement(AFSocketCapability.CAPABILITY_UNIX_DOMAIN)
3434
@AvailabilityRequirement(classes = "java.net.UnixDomainSocketAddress", //
3535
message = "This test requires Java 16 or later")
36-
@SuppressFBWarnings("NM_SAME_SIMPLE_NAME_AS_SUPERCLASS")
36+
@SuppressFBWarnings({"NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", "PATH_TRAVERSAL_IN"})
3737
public final class SocketChannelTest extends
3838
org.newsclub.net.unix.SocketChannelTest<SocketAddress> {
3939

junixsocket-darwin/src/test/java/org/newsclub/net/unix/darwin/system/UtunTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.newsclub.net.unix.AFSocketCapability;
4343
import org.newsclub.net.unix.AFSocketCapabilityRequirement;
4444

45+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
4546
import com.kohlschutter.testutil.ExecutionEnvironmentRequirement;
4647
import com.kohlschutter.testutil.ExecutionEnvironmentRequirement.Rule;
4748

@@ -54,6 +55,7 @@
5455
* @author Christian Kohlschütter
5556
*/
5657
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
58+
@SuppressFBWarnings("COMMAND_INJECTION")
5759
public class UtunTest {
5860
private static final Inet4Address UTUN_SRC_IP;
5961
private static final Inet4Address UTUN_DST_IP;

junixsocket-demo/src/main/java/org/newsclub/net/unix/demo/DemoHelper.java

+4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
import org.newsclub.net.unix.AFUNIXSocketAddress;
3333

3434
import com.kohlschutter.annotations.compiletime.ExcludeFromCodeCoverageGeneratedReport;
35+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
3536

3637
/**
3738
* Just a helper class to simplify controlling the demo from the command line.
3839
*/
40+
@SuppressFBWarnings({"UNENCRYPTED_SOCKET", "PATH_TRAVERSAL_IN"})
3941
public final class DemoHelper {
4042
@ExcludeFromCodeCoverageGeneratedReport(reason = "unreachable")
4143
private DemoHelper() {
@@ -194,6 +196,7 @@ public static Socket connectSocket(SocketAddress socketAddress) throws IOExcepti
194196
}
195197
}
196198

199+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
197200
public static SocketAddress parseAddress(String[] args, SocketAddress defaultAddress)
198201
throws IOException {
199202
if (args.length == 0) {
@@ -205,6 +208,7 @@ public static SocketAddress parseAddress(String[] args, SocketAddress defaultAdd
205208
}
206209
}
207210

211+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
208212
public static SocketAddress parseAddress(String opt, String val, SocketAddress defaultAddress)
209213
throws IOException {
210214
if (opt == null || val == null) {

junixsocket-demo/src/main/java/org/newsclub/net/unix/demo/client/DemoClient.java

+3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
import org.newsclub.net.unix.AFSocket;
2424
import org.newsclub.net.unix.demo.DemoHelper;
2525

26+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
27+
2628
/**
2729
* A demo program to configure and run several {@link AFSocket} client demos from the command line.
2830
*
2931
* @author Christian Kohlschütter
3032
*/
33+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
3134
public final class DemoClient {
3235
public static void main(String[] args) throws IOException, InterruptedException {
3336
final DemoClientBase demoClient;

junixsocket-demo/src/main/java/org/newsclub/net/unix/demo/client/DemoClientBase.java

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.newsclub.net.unix.AFSocketAddress;
2525
import org.newsclub.net.unix.AFUNIXSocket;
2626

27+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
28+
2729
/**
2830
* An {@link AFUNIXSocket} client that's just good for demo purposes.
2931
*
@@ -38,6 +40,7 @@ public void close() throws IOException {
3840
}
3941
}
4042

43+
@SuppressFBWarnings("UNENCRYPTED_SOCKET")
4144
public void connect(SocketAddress endpoint) throws IOException {
4245
System.out.println("Connect " + this + " to " + endpoint);
4346
if (endpoint instanceof AFSocketAddress) {

junixsocket-demo/src/main/java/org/newsclub/net/unix/demo/nanohttpd/NanoHttpdServerDemo.java

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.newsclub.net.unix.demo.DemoHelper;
2929
import org.newsclub.net.unix.demo.okhttp.OkHttpClientDemo;
3030

31+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
32+
3133
import fi.iki.elonen.NanoHTTPD;
3234

3335
/**
@@ -38,6 +40,7 @@
3840
* @author Christian Kohlschütter
3941
* @see OkHttpClientDemo
4042
*/
43+
@SuppressFBWarnings("UNENCRYPTED_SERVER_SOCKET")
4144
public final class NanoHttpdServerDemo extends NanoHTTPD {
4245

4346
public NanoHttpdServerDemo(SocketAddress socketAddress) throws IOException {
@@ -62,6 +65,7 @@ public ServerSocket create() throws IOException {
6265
}
6366
}
6467

68+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
6569
public static void main(String[] args) throws IOException {
6670
SocketAddress addr = DemoHelper.parseAddress(args, //
6771
AFUNIXSocketAddress.of(new File("/tmp/junixsocket-http-server.sock")));

junixsocket-demo/src/main/java/org/newsclub/net/unix/demo/netty/EchoServer.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.newsclub.net.unix.AFUNIXSelectorProvider;
2626
import org.newsclub.net.unix.AFUNIXSocketAddress;
2727

28+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
29+
2830
import io.netty.bootstrap.ServerBootstrap;
2931
import io.netty.channel.ChannelFuture;
3032
import io.netty.channel.ChannelInitializer;
@@ -41,6 +43,7 @@
4143
* guide for 4.x</a>
4244
*/
4345
@SuppressWarnings("FutureReturnValueIgnored" /* errorprone */)
46+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
4447
public class EchoServer {
4548
private final AFSocketAddress addr;
4649

@@ -81,6 +84,7 @@ public void initChannel(SocketChannel ch) throws Exception {
8184
}
8285
}
8386

87+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
8488
public static void main(String[] args) throws Exception {
8589
File path = new File("/tmp/nettyecho");
8690
if (args.length > 0) {

junixsocket-demo/src/main/java/org/newsclub/net/unix/demo/okhttp/OkHttpClientDemo.java

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.newsclub.net.unix.demo.DemoHelper;
2929
import org.newsclub.net.unix.demo.nanohttpd.NanoHttpdServerDemo;
3030

31+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
3132
import com.kohlschutter.util.IOUtil;
3233

3334
import okhttp3.OkHttpClient;
@@ -45,6 +46,7 @@
4546
* @see NanoHttpdServerDemo
4647
*/
4748
public class OkHttpClientDemo {
49+
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
4850
public static void main(String[] args) throws IOException {
4951
SocketAddress addr = DemoHelper.parseAddress(args, //
5052
AFUNIXSocketAddress.of(new File("/tmp/junixsocket-http-server.sock")));

0 commit comments

Comments
 (0)