Skip to content

Commit 255b463

Browse files
committed
Merge branch 'master' into 3.0.0
2 parents 07a377c + 62e6b5c commit 255b463

6 files changed

Lines changed: 70 additions & 114 deletions

File tree

pom.xml

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<parent>
2323
<groupId>org.apache</groupId>
2424
<artifactId>apache</artifactId>
25-
<version>34</version>
25+
<version>35</version>
2626
</parent>
2727

2828
<groupId>org.apache.sshd</groupId>
@@ -89,7 +89,7 @@
8989
<maven.compiler.source>${javac.source}</maven.compiler.source>
9090
<ant.version>1.10.15</ant.version>
9191
<ant.build.javac.source>${javac.source}</ant.build.javac.source>
92-
<build-helper-maven-plugin.version>3.6.0</build-helper-maven-plugin.version>
92+
<build-helper-maven-plugin.version>3.6.1</build-helper-maven-plugin.version>
9393

9494
<javac.target>${javac.source}</javac.target>
9595
<required.java.version>[${javac.target},)</required.java.version>
@@ -98,9 +98,9 @@
9898
<ant.build.javac.target>${javac.target}</ant.build.javac.target>
9999

100100
<groovy.version>4.0.17</groovy.version>
101-
<bouncycastle.version>1.80</bouncycastle.version>
101+
<bouncycastle.version>1.81</bouncycastle.version>
102102
<!-- NOTE: upgrading slf4j beyond this version causes
103-
103+
104104
Execution verify-style of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.2:check failed.: NullPointerException
105105
-->
106106
<slf4j.version>1.7.36</slf4j.version>
@@ -112,14 +112,13 @@
112112
<jgit.version>5.13.3.202401111512-r</jgit.version>
113113
<!-- mockito 5.0 requires Java 11. -->
114114
<mockito.version>4.11.0</mockito.version>
115-
<bytebuddy.version>1.17.5</bytebuddy.version>
116-
<testcontainers.version>1.21.0</testcontainers.version>
117-
<grpc.version>1.73.0</grpc.version> <!-- Used only in tests -->
115+
<testcontainers.version>1.21.3</testcontainers.version>
116+
<grpc.version>1.74.0</grpc.version> <!-- Used only in tests -->
118117

119118
<maven.archiver.version>3.6.3</maven.archiver.version>
120119
<plexus.archiver.version>4.10.0</plexus.archiver.version>
121120
<!-- See https://pmd.github.io/ for available latest version -->
122-
<pmd.version>7.14.0</pmd.version>
121+
<pmd.version>7.16.0</pmd.version>
123122
<japicmp.version>0.23.1</japicmp.version>
124123
<sshd.tests.timeout.factor>1.0</sshd.tests.timeout.factor>
125124
<sshd.tests.rerun.count>2</sshd.tests.rerun.count>
@@ -138,7 +137,7 @@
138137
<format.formatter.action>validate</format.formatter.action>
139138
</properties>
140139
</profile>
141-
140+
142141
<profile>
143142
<id>toolchains</id>
144143
<activation>
@@ -222,7 +221,7 @@
222221
<plugin>
223222
<groupId>org.owasp</groupId>
224223
<artifactId>dependency-check-maven</artifactId>
225-
<version>12.1.1</version>
224+
<version>12.1.3</version>
226225
<!-- see https://jeremylong.github.io/DependencyCheck/dependency-check-maven/configuration.html -->
227226
<configuration>
228227
<!-- see https://github.com/jeremylong/DependencyCheck/issues/1394 -->
@@ -276,7 +275,7 @@
276275
<dependency>
277276
<groupId>com.google.errorprone</groupId>
278277
<artifactId>error_prone_core</artifactId>
279-
<version>2.38.0</version>
278+
<version>2.41.0</version>
280279
</dependency>
281280
</dependencies>
282281
</plugin>
@@ -562,23 +561,6 @@
562561
<version>2.27.2</version>
563562
</dependency>
564563

565-
<!-- Transitive dependencies by various 3rd party packages -->
566-
<dependency>
567-
<groupId>commons-io</groupId>
568-
<artifactId>commons-io</artifactId>
569-
<version>2.19.0</version>
570-
</dependency>
571-
<dependency>
572-
<groupId>commons-lang</groupId>
573-
<artifactId>commons-lang</artifactId>
574-
<version>2.6</version>
575-
</dependency>
576-
<dependency>
577-
<groupId>commons-collections</groupId>
578-
<artifactId>commons-collections</artifactId>
579-
<version>3.2.2</version>
580-
</dependency>
581-
582564
<dependency>
583565
<groupId>org.springframework</groupId>
584566
<artifactId>spring-core</artifactId>
@@ -599,30 +581,6 @@
599581
<scope>import</scope>
600582
</dependency>
601583

602-
<!-- Referenced indirectly by Bytebuddy -->
603-
<dependency>
604-
<groupId>com.google.code.findbugs</groupId>
605-
<artifactId>jsr305</artifactId>
606-
<version>3.0.2</version>
607-
</dependency>
608-
609-
<!-- Used by mockito -->
610-
<dependency>
611-
<groupId>net.bytebuddy</groupId>
612-
<artifactId>byte-buddy</artifactId>
613-
<version>${bytebuddy.version}</version>
614-
</dependency>
615-
<dependency>
616-
<groupId>net.bytebuddy</groupId>
617-
<artifactId>byte-buddy-agent</artifactId>
618-
<version>${bytebuddy.version}</version>
619-
</dependency>
620-
621-
<dependency>
622-
<groupId>net.sf.jpam</groupId>
623-
<artifactId>jpam</artifactId>
624-
<version>1.1</version>
625-
</dependency>
626584
<dependency>
627585
<groupId>commons-httpclient</groupId>
628586
<artifactId>commons-httpclient</artifactId>
@@ -703,7 +661,7 @@
703661
<dependency>
704662
<groupId>org.junit.jupiter</groupId>
705663
<artifactId>junit-jupiter</artifactId>
706-
<version>5.13.3</version>
664+
<version>5.13.4</version>
707665
</dependency>
708666
<dependency>
709667
<groupId>org.mockito</groupId>
@@ -1059,7 +1017,7 @@
10591017
<plugin>
10601018
<groupId>net.revelc.code.formatter</groupId>
10611019
<artifactId>formatter-maven-plugin</artifactId>
1062-
<version>2.26.0</version>
1020+
<version>2.27.0</version>
10631021
<configuration>
10641022
<skipXmlFormatting>true</skipXmlFormatting>
10651023
<skipHtmlFormatting>true</skipHtmlFormatting>
@@ -1403,7 +1361,7 @@
14031361
</plugin>
14041362
</plugins>
14051363
</build>
1406-
1364+
14071365
<distributionManagement>
14081366
<site>
14091367
<id>github</id>

sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.EnumSet;
2828
import java.util.Objects;
2929
import java.util.Set;
30-
import java.util.concurrent.TimeUnit;
3130
import java.util.concurrent.atomic.AtomicBoolean;
3231
import java.util.concurrent.atomic.AtomicReference;
3332

@@ -262,6 +261,7 @@ public Set<ClientChannelEvent> waitFor(Collection<ClientChannelEvent> mask, long
262261
if (timeout > 0L) {
263262
long now = System.currentTimeMillis();
264263
long usedTime = now - startTime;
264+
remWait = timeout - usedTime;
265265
if ((usedTime >= timeout) || (remWait <= 0L)) {
266266
if (traceEnabled) {
267267
log.trace("waitFor({}) call timeout {}/{} for mask={}: {}",
@@ -290,14 +290,6 @@ public Set<ClientChannelEvent> waitFor(Collection<ClientChannelEvent> mask, long
290290
if (traceEnabled) {
291291
log.trace("waitFor({}) lock notified on channel after {} nanos", this, nanoDuration);
292292
}
293-
294-
if (timeout > 0L) {
295-
long waitDuration = TimeUnit.MILLISECONDS.convert(nanoDuration, TimeUnit.NANOSECONDS);
296-
if (waitDuration <= 0L) {
297-
waitDuration = 123L;
298-
}
299-
remWait -= waitDuration;
300-
}
301293
} catch (InterruptedException e) {
302294
long nanoEnd = System.nanoTime();
303295
long nanoDuration = nanoEnd - nanoStart;

sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Map;
2929
import java.util.Objects;
3030
import java.util.Set;
31-
import java.util.concurrent.TimeUnit;
3231
import java.util.concurrent.atomic.AtomicBoolean;
3332
import java.util.concurrent.atomic.AtomicReference;
3433

@@ -261,6 +260,7 @@ public Set<ClientSessionEvent> waitFor(Collection<ClientSessionEvent> mask, long
261260
if (timeout > 0L) {
262261
long now = System.currentTimeMillis();
263262
long usedTime = now - startTime;
263+
remWait = timeout - usedTime;
264264
if ((usedTime >= timeout) || (remWait <= 0L)) {
265265
if (traceEnabled) {
266266
log.trace("waitFor({}) call timeout {}/{} for mask={}: {}",
@@ -289,14 +289,6 @@ public Set<ClientSessionEvent> waitFor(Collection<ClientSessionEvent> mask, long
289289
if (traceEnabled) {
290290
log.trace("waitFor({}) Lock notified after {} nanos", this, nanoDuration);
291291
}
292-
293-
if (timeout > 0L) {
294-
long waitDuration = TimeUnit.MILLISECONDS.convert(nanoDuration, TimeUnit.NANOSECONDS);
295-
if (waitDuration <= 0L) {
296-
waitDuration = 123L;
297-
}
298-
remWait -= waitDuration;
299-
}
300292
} catch (InterruptedException e) {
301293
long nanoEnd = System.nanoTime();
302294
long nanoDuration = nanoEnd - nanoStart;

sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwarder.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -746,31 +746,23 @@ protected InetSocketAddress doBind(SshdSocketAddress address, IoAcceptor accepto
746746
throws IOException {
747747
// TODO find a better way to determine the resulting bind address - what if multi-threaded calls...
748748
Collection<SocketAddress> before = acceptor.getBoundAddresses();
749-
try {
750-
InetSocketAddress bindAddress = address.toInetSocketAddress();
751-
acceptor.bind(bindAddress);
749+
InetSocketAddress bindAddress = address.toInetSocketAddress();
750+
acceptor.bind(bindAddress);
752751

753-
Collection<SocketAddress> after = acceptor.getBoundAddresses();
754-
if (GenericUtils.size(after) > 0) {
755-
after.removeAll(before);
756-
}
757-
if (GenericUtils.isEmpty(after)) {
758-
throw new IOException("Error binding to " + address + "[" + bindAddress + "]: no local addresses bound");
759-
}
760-
761-
if (after.size() > 1) {
762-
throw new IOException("Multiple local addresses have been bound for " + address + "[" + bindAddress + "]");
763-
}
752+
Collection<SocketAddress> after = acceptor.getBoundAddresses();
753+
if (GenericUtils.size(after) > 0) {
754+
after.removeAll(before);
755+
}
756+
if (GenericUtils.isEmpty(after)) {
757+
throw new IOException("Error binding to " + address + "[" + bindAddress + "]: no local addresses bound");
758+
}
764759

765-
InetSocketAddress boundAddress = (InetSocketAddress) GenericUtils.head(after);
766-
return boundAddress;
767-
} catch (IOException bindErr) {
768-
Collection<SocketAddress> after = acceptor.getBoundAddresses();
769-
if (GenericUtils.isEmpty(after)) {
770-
close();
771-
}
772-
throw bindErr;
760+
if (after.size() > 1) {
761+
throw new IOException("Multiple local addresses have been bound for " + address + "[" + bindAddress + "]");
773762
}
763+
764+
InetSocketAddress boundAddress = (InetSocketAddress) GenericUtils.head(after);
765+
return boundAddress;
774766
}
775767

776768
@Override

sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.apache.sshd.common.session.ConnectionService;
7272
import org.apache.sshd.common.util.GenericUtils;
7373
import org.apache.sshd.common.util.MapEntryUtils.NavigableMapBuilder;
74+
import org.apache.sshd.common.util.OsUtils;
7475
import org.apache.sshd.common.util.ProxyUtils;
7576
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
7677
import org.apache.sshd.common.util.io.IoUtils;
@@ -699,6 +700,27 @@ void localForwardingNativeReuse() throws Exception {
699700
}
700701
}
701702

703+
@Test // GH-754 : forwarder should _not_ be closed after bind error
704+
void localForwardingNativeError() throws Exception {
705+
Assumptions.assumeFalse(OsUtils.isWin32(), "Privileged port can be bound on Windows");
706+
try (ClientSession session = createNativeSession(null)) {
707+
// Use a privileged port to provoke an exception
708+
SshdSocketAddress local = new SshdSocketAddress(TEST_LOCALHOST, 22);
709+
SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort);
710+
try {
711+
SshdSocketAddress bound = session.startLocalPortForwarding(local, remote);
712+
// If we get here, we have a problem
713+
session.stopLocalPortForwarding(bound);
714+
fail("Expected an exception (privileged port)");
715+
} catch (IOException e) {
716+
local = new SshdSocketAddress("", 0);
717+
SshdSocketAddress bound = session.startLocalPortForwarding(local, remote);
718+
assertNotNull(bound);
719+
session.stopLocalPortForwarding(bound);
720+
}
721+
}
722+
}
723+
702724
@Test
703725
void localForwardingNativeBigPayload() throws Exception {
704726
try (ClientSession session = createNativeSession(null)) {

sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,27 @@ public void run() {
8282

8383
Path rootDir = resolveRootDirectory(command, args);
8484
RepositoryCache.FileKey key = RepositoryCache.FileKey.lenient(rootDir.toFile(), FS.DETECTED);
85-
Repository db = key.open(true /* must exist */);
86-
String subCommand = args[0];
87-
if (RemoteConfig.DEFAULT_UPLOAD_PACK.equals(subCommand)) {
88-
UploadPack uploadPack = new UploadPack(db);
89-
packConfiguration.configureUploadPack(getSession(), uploadPack);
90-
Environment environment = getEnvironment();
91-
Map<String, String> envVars = environment.getEnv();
92-
String protocol = MapEntryUtils.isEmpty(envVars)
93-
? null : envVars.get(GitProtocolConstants.PROTOCOL_ENVIRONMENT_VARIABLE);
94-
if (GenericUtils.isNotBlank(protocol)) {
95-
uploadPack.setExtraParameters(Collections.singleton(protocol));
85+
try (Repository db = key.open(true /* must exist */)) {
86+
String subCommand = args[0];
87+
if (RemoteConfig.DEFAULT_UPLOAD_PACK.equals(subCommand)) {
88+
UploadPack uploadPack = new UploadPack(db);
89+
packConfiguration.configureUploadPack(getSession(), uploadPack);
90+
Environment environment = getEnvironment();
91+
Map<String, String> envVars = environment.getEnv();
92+
String protocol = MapEntryUtils.isEmpty(envVars)
93+
? null : envVars.get(GitProtocolConstants.PROTOCOL_ENVIRONMENT_VARIABLE);
94+
if (GenericUtils.isNotBlank(protocol)) {
95+
uploadPack.setExtraParameters(Collections.singleton(protocol));
96+
}
97+
uploadPack.upload(getInputStream(), getOutputStream(), getErrorStream());
98+
} else if (RemoteConfig.DEFAULT_RECEIVE_PACK.equals(subCommand)) {
99+
ReceivePack receivePack = new ReceivePack(db);
100+
packConfiguration.configureReceivePack(getSession(), receivePack);
101+
receivePack.receive(getInputStream(), getOutputStream(), getErrorStream());
102+
} else {
103+
throw new IllegalArgumentException("Unknown git command: " + command);
96104
}
97-
uploadPack.upload(getInputStream(), getOutputStream(), getErrorStream());
98-
} else if (RemoteConfig.DEFAULT_RECEIVE_PACK.equals(subCommand)) {
99-
ReceivePack receivePack = new ReceivePack(db);
100-
packConfiguration.configureReceivePack(getSession(), receivePack);
101-
receivePack.receive(getInputStream(), getOutputStream(), getErrorStream());
102-
} else {
103-
throw new IllegalArgumentException("Unknown git command: " + command);
104105
}
105-
106106
onExit(0);
107107
} catch (Throwable t) {
108108
onExit(-1, t.getClass().getSimpleName());

0 commit comments

Comments
 (0)