Add EOL at end of appended known-hosts file entry
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/6256245d Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/6256245d Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/6256245d Branch: refs/heads/master Commit: 6256245da6308a0aa4f94c9a3813a4d5d38b2c9e Parents: 2119f79 Author: Goldstein Lyor <[email protected]> Authored: Mon May 15 16:51:21 2017 +0300 Committer: Lyor Goldstein <[email protected]> Committed: Mon May 15 19:38:22 2017 +0300 ---------------------------------------------------------------------- .../sshd/client/keyverifier/KnownHostsServerKeyVerifier.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6256245d/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java index 8dd6ca6..1fc9429 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java @@ -637,12 +637,15 @@ public class KnownHostsServerKeyVerifier String line = entry.getConfigLine(); byte[] lineData = line.getBytes(StandardCharsets.UTF_8); boolean reuseExisting = Files.exists(file) && (Files.size(file) > 0); + byte[] eolBytes = IoUtils.getEOLBytes(); synchronized (updateLock) { try (OutputStream output = reuseExisting ? Files.newOutputStream(file, StandardOpenOption.APPEND) : Files.newOutputStream(file)) { if (reuseExisting) { - output.write(IoUtils.getEOLBytes()); // separate from previous lines + output.write(eolBytes); // separate from previous lines } + output.write(lineData); + output.write(eolBytes); // add another separator for trailing lines - in case regular SSH client appends to it } }
