Repository: mina-sshd Updated Branches: refs/heads/master 28c52e91c -> 8ec4b9c36
[SSHD-846] Nullify AbstractSession KEX instance before marking state as DONE to avoid race condition and possible NPE Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/8ec4b9c3 Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/8ec4b9c3 Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/8ec4b9c3 Branch: refs/heads/master Commit: 8ec4b9c36cd28e40cc81cf9f13f30706459295c9 Parents: 29d7712 Author: Goldstein Lyor <[email protected]> Authored: Tue Oct 2 18:01:14 2018 +0300 Committer: Lyor Goldstein <[email protected]> Committed: Wed Oct 3 20:05:17 2018 +0300 ---------------------------------------------------------------------- .../sshd/common/session/helpers/AbstractSession.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8ec4b9c3/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java index 287c8cd..ce4c3fe 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java @@ -849,9 +849,11 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen Map<KexProposalOption, String> result = negotiate(); String kexAlgorithm = result.get(KexProposalOption.ALGORITHMS); Collection<? extends NamedFactory<KeyExchange>> kexFactories = getKeyExchangeFactories(); - kex = ValidateUtils.checkNotNull(NamedFactory.create(kexFactories, kexAlgorithm), - "Unknown negotiated KEX algorithm: %s", - kexAlgorithm); + synchronized (pendingPackets) { + kex = ValidateUtils.checkNotNull(NamedFactory.create(kexFactories, kexAlgorithm), + "Unknown negotiated KEX algorithm: %s", + kexAlgorithm); + } byte[] v_s = serverVersion.getBytes(StandardCharsets.UTF_8); byte[] v_c = clientVersion.getBytes(StandardCharsets.UTF_8); @@ -889,8 +891,8 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen Collection<? extends Map.Entry<? extends SshFutureListener<IoWriteFuture>, IoWriteFuture>> pendingWrites; synchronized (pendingPackets) { pendingWrites = sendPendingPackets(pendingPackets); - kexState.set(KexState.DONE); kex = null; // discard and GC since KEX is completed + kexState.set(KexState.DONE); } int pendingCount = pendingWrites.size();
