You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2017/06/25 05:43:22 UTC
mina-sshd git commit: Updated findbugs check parameters
Repository: mina-sshd
Updated Branches:
refs/heads/master 77af61d35 -> 4554b304e
Updated findbugs check parameters
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/4554b304
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/4554b304
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/4554b304
Branch: refs/heads/master
Commit: 4554b304e89696481f26fa94b4d471bb974fe3d0
Parents: 77af61d
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Fri Jun 23 12:20:45 2017 +0300
Committer: Goldstein Lyor <ly...@c-b4.com>
Committed: Sun Jun 25 08:43:09 2017 +0300
----------------------------------------------------------------------
pom.xml | 11 ++++---
.../keys/loader/putty/PuttyKeyReader.java | 7 +++-
.../client/auth/pubkey/UserAuthPublicKey.java | 10 ++++--
.../client/simple/AbstractSimpleClient.java | 11 ++-----
.../subsystem/sftp/DefaultCloseableHandle.java | 10 ++++++
.../common/config/keys/AuthorizedKeyEntry.java | 10 ++++++
.../apache/sshd/common/util/GenericUtils.java | 16 ++++++++-
sshd-findbugs.xml | 34 ++++++++++++++++++++
.../apache/sshd/git/pack/GitPackCommand.java | 21 ++++++------
.../org/apache/sshd/git/pgm/GitPgmCommand.java | 20 ++++++------
10 files changed, 110 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4554b304/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 91da588..e420c3d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -119,10 +119,6 @@
<httpcomps.version>4.4.1</httpcomps.version>
</properties>
- <prerequisites>
- <maven>${min.required.maven.version}</maven>
- </prerequisites>
-
<profiles>
<profile>
<id>quick</id>
@@ -138,6 +134,12 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <xmlOutput>true</xmlOutput>
+ <fork>false</fork>
+ <includeTests>true</includeTests>
+ <includeFilterFile>${workspace.root.dir}${file.separator}sshd-findbugs.xml</includeFilterFile>
+ </configuration>
<executions>
<execution>
<id>run-findbugs</id>
@@ -484,6 +486,7 @@
<exclude>src/test/resources/**</exclude>
<exclude>**/stty-output-*.txt</exclude>
<exclude>*checkstyle*</exclude>
+ <exclude>*findbugs*</exclude>
<exclude>**/big-msg.txt</exclude>
<!-- Eclipse files -->
<exclude>.metadata/**</exclude>
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4554b304/sshd-contrib/src/main/java/org/apache/sshd/common/config/keys/loader/putty/PuttyKeyReader.java
----------------------------------------------------------------------
diff --git a/sshd-contrib/src/main/java/org/apache/sshd/common/config/keys/loader/putty/PuttyKeyReader.java b/sshd-contrib/src/main/java/org/apache/sshd/common/config/keys/loader/putty/PuttyKeyReader.java
index ae00ef2..9f1bd73 100644
--- a/sshd-contrib/src/main/java/org/apache/sshd/common/config/keys/loader/putty/PuttyKeyReader.java
+++ b/sshd-contrib/src/main/java/org/apache/sshd/common/config/keys/loader/putty/PuttyKeyReader.java
@@ -23,6 +23,7 @@ import java.io.Closeable;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StreamCorruptedException;
import java.math.BigInteger;
/**
@@ -37,7 +38,11 @@ public class PuttyKeyReader implements Closeable {
}
public void skip() throws IOException {
- di.skipBytes(di.readInt());
+ int skipSize = di.readInt();
+ int effectiveSkip = di.skipBytes(skipSize);
+ if (skipSize != effectiveSkip) {
+ throw new StreamCorruptedException("Mismatched skip size: expected" + skipSize + ", actual=" + effectiveSkip);
+ }
}
private byte[] read() throws IOException {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4554b304/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKey.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKey.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKey.java
index f8a9b67..2bd6472 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKey.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKey.java
@@ -45,9 +45,9 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
public class UserAuthPublicKey extends AbstractUserAuth implements SignatureFactoriesManager {
public static final String NAME = UserAuthPublicKeyFactory.NAME;
- private Iterator<PublicKeyIdentity> keys;
- private PublicKeyIdentity current;
- private List<NamedFactory<Signature>> factories;
+ protected Iterator<PublicKeyIdentity> keys;
+ protected PublicKeyIdentity current;
+ protected List<NamedFactory<Signature>> factories;
public UserAuthPublicKey() {
this(null);
@@ -124,12 +124,14 @@ public class UserAuthPublicKey extends AbstractUserAuth implements SignatureFact
throw new RuntimeSshException(e);
}
+
String algo = KeyUtils.getKeyType(key);
String name = getName();
if (log.isDebugEnabled()) {
log.debug("sendAuthDataRequest({})[{}] send SSH_MSG_USERAUTH_REQUEST request {} type={} - fingerprint={}",
session, service, name, algo, KeyUtils.getFingerPrint(key));
}
+
Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST);
buffer.putString(session.getUsername());
buffer.putString(service);
@@ -166,6 +168,7 @@ public class UserAuthPublicKey extends AbstractUserAuth implements SignatureFact
throw new RuntimeSshException(e);
}
+
String algo = KeyUtils.getKeyType(key);
String rspKeyType = buffer.getString();
if (!rspKeyType.equals(algo)) {
@@ -196,6 +199,7 @@ public class UserAuthPublicKey extends AbstractUserAuth implements SignatureFact
buffer.putString(algo);
buffer.putPublicKey(key);
appendSignature(session, service, name, username, algo, key, buffer);
+
session.writePacket(buffer);
return true;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4554b304/sshd-core/src/main/java/org/apache/sshd/client/simple/AbstractSimpleClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/simple/AbstractSimpleClient.java b/sshd-core/src/main/java/org/apache/sshd/client/simple/AbstractSimpleClient.java
index 904b7ec..475c9d4 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/simple/AbstractSimpleClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/simple/AbstractSimpleClient.java
@@ -56,7 +56,7 @@ public abstract class AbstractSimpleClient extends AbstractLoggingBean implement
protected SftpClient createSftpClient(final ClientSession session) throws IOException {
Exception err = null;
try {
- final SftpClient client = session.createSftpClient();
+ SftpClient client = session.createSftpClient();
try {
return createSftpClient(session, client);
} catch (Exception e) {
@@ -191,7 +191,7 @@ public abstract class AbstractSimpleClient extends AbstractLoggingBean implement
return createScpClient(sessionLogin(target, username, identity));
}
- protected CloseableScpClient createScpClient(final ClientSession session) throws IOException {
+ protected CloseableScpClient createScpClient(ClientSession session) throws IOException {
try {
ScpClient client = Objects.requireNonNull(session, "No client session").createScpClient();
ClassLoader loader = getClass().getClassLoader();
@@ -230,12 +230,7 @@ public abstract class AbstractSimpleClient extends AbstractLoggingBean implement
e.addSuppressed(t);
}
- if (e instanceof IOException) {
- throw (IOException) e;
- } else {
- throw new IOException(e);
- }
+ throw GenericUtils.toIOException(e);
}
}
-
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4554b304/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultCloseableHandle.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultCloseableHandle.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultCloseableHandle.java
index 6f4b14e..67ad906 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultCloseableHandle.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultCloseableHandle.java
@@ -52,4 +52,14 @@ public class DefaultCloseableHandle extends CloseableHandle {
client.close(this);
}
}
+
+ @Override // to avoid Findbugs[EQ_DOESNT_OVERRIDE_EQUALS]
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override // to avoid Findbugs[EQ_DOESNT_OVERRIDE_EQUALS]
+ public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4554b304/sshd-core/src/main/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntry.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntry.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntry.java
index ac4ddde..342f831 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntry.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntry.java
@@ -125,6 +125,16 @@ public class AuthorizedKeyEntry extends PublicKeyEntry {
return key;
}
+ @Override // to avoid Findbugs[EQ_DOESNT_OVERRIDE_EQUALS]
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override // to avoid Findbugs[EQ_DOESNT_OVERRIDE_EQUALS]
+ public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
+
@Override
public String toString() {
String entry = super.toString();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4554b304/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
index 28456f9..39036b8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
@@ -19,6 +19,7 @@
package org.apache.sshd.common.util;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.ArrayList;
@@ -140,7 +141,7 @@ public final class GenericUtils {
}
public static int safeCompare(String s1, String s2, boolean caseSensitive) {
- if (s1 == s2) {
+ if (isSameReference(s1, s2)) {
return 0;
} else if (s1 == null) {
return +1; // push null(s) to end
@@ -153,6 +154,10 @@ public final class GenericUtils {
}
}
+ public static <T> boolean isSameReference(T o1, T o2) {
+ return o1 == o2;
+ }
+
public static int length(CharSequence cs) {
return cs == null ? 0 : cs.length();
}
@@ -731,6 +736,7 @@ public final class GenericUtils {
return t; // no special handling required or available
}
+
/**
* @param t The original {@link Throwable} - ignored if {@code null}
* @return If {@link Throwable#getCause()} is non-{@code null} then
@@ -775,6 +781,14 @@ public final class GenericUtils {
return current;
}
+ public static IOException toIOException(Throwable e) {
+ if (e instanceof IOException) {
+ return (IOException) e;
+ } else {
+ return new IOException(e);
+ }
+ }
+
/**
* Wraps a value into a {@link Supplier}
* @param <T> Type of value being supplied
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4554b304/sshd-findbugs.xml
----------------------------------------------------------------------
diff --git a/sshd-findbugs.xml b/sshd-findbugs.xml
new file mode 100644
index 0000000..1e1f3a1
--- /dev/null
+++ b/sshd-findbugs.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<FindBugsFilter>
+ <!-- See http://findbugs.sourceforge.net/manual/filter.html for available format options -->
+
+ <Match>
+ <!-- Exclude Groovy files -->
+ <Source name="~.*\.groovy" />
+ </Match>
+
+ <!-- See http://findbugs.sourceforge.net/bugDescriptions.html for available built-in bug codes and patterns -->
+
+ <Match>
+ <Bug code="BIT,CN,Co,DMI,ES,FS,HE,ISC,ME,RR" />
+ </Match>
+
+ <Match>
+ <Bug pattern="BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS,BC_IMPOSSIBLE_CAST,BC_IMPOSSIBLE_DOWNCAST" />
+ </Match>
+ <Match>
+ <Bug pattern="BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY,BC_IMPOSSIBLE_INSTANCEOF" />
+ </Match>
+
+ <Match>
+ <Bug pattern="DM_NEW_FOR_GETCLASS" />
+ </Match>
+
+ <Match>
+ <Bug pattern="EQ_ABSTRACT_SELF,EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS,EQ_SELF_NO_OBJECT,EQ_ALWAYS_FALSE,EQ_ALWAYS_TRUE,EQ_COMPARING_CLASS_NAMES" />
+ </Match>
+ <Match>
+ <Bug pattern="EQ_OTHER_NO_OBJECT,EQ_OTHER_USE_OBJECT,EQ_SELF_USE_OBJECT,EQ_DOESNT_OVERRIDE_EQUALS" />
+ </Match>
+
+</FindBugsFilter>
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4554b304/sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java
----------------------------------------------------------------------
diff --git a/sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java b/sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java
index 500e020..229cbfb 100644
--- a/sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java
+++ b/sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java
@@ -155,39 +155,35 @@ public class GitPackCommand extends AbstractLoggingBean implements Command, Runn
}
List<String> list = new ArrayList<>();
-
StringBuilder sb = new StringBuilder();
-
int expecting = CHAR | DELIMITER | STARTQUOTE;
-
boolean isEscaped = false;
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
-
boolean isDelimiter = delim.indexOf(c) >= 0;
-
- if (!isEscaped && c == '\\') {
+ if (!isEscaped && (c == '\\')) {
isEscaped = true;
continue;
}
if (isEscaped) {
sb.append(c);
- } else if (isDelimiter && (expecting & DELIMITER) > 0) {
+ } else if (isDelimiter && ((expecting & DELIMITER) != 0)) {
if (trim) {
- list.add(sb.toString().trim());
+ String str = sb.toString();
+ list.add(str.trim());
} else {
list.add(sb.toString());
}
sb.delete(0, sb.length());
expecting = CHAR | DELIMITER | STARTQUOTE;
- } else if ((c == '"') && (expecting & STARTQUOTE) > 0) {
+ } else if ((c == '"') && ((expecting & STARTQUOTE) != 0)) {
sb.append(c);
expecting = CHAR | ENDQUOTE;
- } else if ((c == '"') && (expecting & ENDQUOTE) > 0) {
+ } else if ((c == '"') && ((expecting & ENDQUOTE) != 0)) {
sb.append(c);
expecting = CHAR | STARTQUOTE | DELIMITER;
- } else if ((expecting & CHAR) > 0) {
+ } else if ((expecting & CHAR) != 0) {
sb.append(c);
} else {
throw new IllegalArgumentException("Invalid delimited string: " + value);
@@ -198,7 +194,8 @@ public class GitPackCommand extends AbstractLoggingBean implements Command, Runn
if (sb.length() > 0) {
if (trim) {
- list.add(sb.toString().trim());
+ String str = sb.toString();
+ list.add(str.trim());
} else {
list.add(sb.toString());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4554b304/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java
----------------------------------------------------------------------
diff --git a/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java b/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java
index 2e6434f..013f4e5 100644
--- a/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java
+++ b/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java
@@ -142,39 +142,36 @@ public class GitPgmCommand extends AbstractLoggingBean implements Command, Runna
}
List<String> list = new ArrayList<>();
-
StringBuilder sb = new StringBuilder();
-
int expecting = CHAR | DELIMITER | STARTQUOTE;
-
boolean isEscaped = false;
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
-
boolean isDelimiter = delim.indexOf(c) >= 0;
- if (!isEscaped && c == '\\') {
+ if (!isEscaped && (c == '\\')) {
isEscaped = true;
continue;
}
if (isEscaped) {
sb.append(c);
- } else if (isDelimiter && (expecting & DELIMITER) > 0) {
+ } else if (isDelimiter && ((expecting & DELIMITER) != 0)) {
if (trim) {
- list.add(sb.toString().trim());
+ String str = sb.toString();
+ list.add(str.trim());
} else {
list.add(sb.toString());
}
sb.delete(0, sb.length());
expecting = CHAR | DELIMITER | STARTQUOTE;
- } else if ((c == '"') && (expecting & STARTQUOTE) > 0) {
+ } else if ((c == '"') && ((expecting & STARTQUOTE) != 0)) {
sb.append(c);
expecting = CHAR | ENDQUOTE;
- } else if ((c == '"') && (expecting & ENDQUOTE) > 0) {
+ } else if ((c == '"') && ((expecting & ENDQUOTE) != 0)) {
sb.append(c);
expecting = CHAR | STARTQUOTE | DELIMITER;
- } else if ((expecting & CHAR) > 0) {
+ } else if ((expecting & CHAR) != 0) {
sb.append(c);
} else {
throw new IllegalArgumentException("Invalid delimited string: " + value);
@@ -185,7 +182,8 @@ public class GitPgmCommand extends AbstractLoggingBean implements Command, Runna
if (sb.length() > 0) {
if (trim) {
- list.add(sb.toString().trim());
+ String str = sb.toString();
+ list.add(str.trim());
} else {
list.add(sb.toString());
}