This is an automated email from the ASF dual-hosted git repository. lgoldstein pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
commit b4fc8db6bc3fdc1907e619cd8b5043e9d2f87e3b Author: Sakthipriyan Vairamani (thefourtheye) <[email protected]> AuthorDate: Sat Feb 9 10:32:29 2019 +0200 [SSHD-890] SFTP susbsystem implementation does not clear response buffer when sending unsupported extension status message --- .../sftp/AbstractSftpSubsystemHelper.java | 2 +- .../sshd/server/subsystem/sftp/SftpSubsystem.java | 2 +- .../sftp/extensions/UnsupportedExtensionTest.java | 71 ++++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java b/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java index 2ef4b60..bd4ece6 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java @@ -1651,7 +1651,7 @@ public abstract class AbstractSftpSubsystemHelper if (log.isDebugEnabled()) { log.debug("executeExtendedCommand({}) received unsupported SSH_FXP_EXTENDED({})", getServerSession(), extension); } - sendStatus(buffer, id, SftpConstants.SSH_FX_OP_UNSUPPORTED, + sendStatus(prepareReply(buffer), id, SftpConstants.SSH_FX_OP_UNSUPPORTED, "Command SSH_FXP_EXTENDED(" + extension + ") is unsupported or not implemented"); } diff --git a/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java b/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java index 66a0ced..e7f1538 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java @@ -947,7 +947,7 @@ public class SftpSubsystem @Override protected Buffer prepareReply(Buffer buffer) { buffer.clear(); - buffer.putInt(0); + buffer.putInt(0); // reserve space for actual packet length return buffer; } diff --git a/sshd-sftp/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/UnsupportedExtensionTest.java b/sshd-sftp/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/UnsupportedExtensionTest.java new file mode 100644 index 0000000..6dcdea0 --- /dev/null +++ b/sshd-sftp/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/UnsupportedExtensionTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sshd.client.subsystem.sftp.extensions; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import org.apache.sshd.client.session.ClientSession; +import org.apache.sshd.client.subsystem.sftp.AbstractSftpClientTestSupport; +import org.apache.sshd.client.subsystem.sftp.RawSftpClient; +import org.apache.sshd.client.subsystem.sftp.SftpClient; +import org.apache.sshd.common.subsystem.sftp.SftpConstants; +import org.apache.sshd.common.util.GenericUtils; +import org.apache.sshd.common.util.buffer.Buffer; +import org.apache.sshd.common.util.buffer.ByteArrayBuffer; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class UnsupportedExtensionTest extends AbstractSftpClientTestSupport { + public UnsupportedExtensionTest() throws IOException { + super(); + } + + @Test // see SSHD-890 + public void testUnsupportedExtension() throws IOException { + try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port) + .verify(7L, TimeUnit.SECONDS) + .getSession()) { + session.addPasswordIdentity(getCurrentTestName()); + session.auth().verify(5L, TimeUnit.SECONDS); + + try (SftpClient sftpClient = createSftpClient(session)) { + String opcode = getCurrentTestName(); + Buffer buffer = new ByteArrayBuffer(Integer.BYTES + GenericUtils.length(opcode) + Byte.SIZE, false); + buffer.putString(opcode); + + assertObjectInstanceOf("Not a raw SFTP client", RawSftpClient.class, sftpClient); + RawSftpClient sftp = (RawSftpClient) sftpClient; + int cmd = sftp.send(SftpConstants.SSH_FXP_EXTENDED, buffer); + Buffer responseBuffer = sftp.receive(cmd); + + responseBuffer.getInt(); // Ignoring length + int type = responseBuffer.getUByte(); + responseBuffer.getInt(); // Ignoring message ID + int substatus = responseBuffer.getInt(); + + assertEquals("Type is not STATUS", SftpConstants.SSH_FXP_STATUS, type); + assertEquals("Sub-Type is not UNSUPPORTED", SftpConstants.SSH_FX_OP_UNSUPPORTED, substatus); + } + } + } +} \ No newline at end of file
