diff options
author | Alex Crichton <alex@alexcrichton.com> | 2015-11-01 09:28:34 -0800 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2015-11-01 09:28:34 -0800 |
commit | 0f210fe845f36d5d6554d2adc593ec65a273f56e (patch) | |
tree | dd39565e8bbfbc4af840063fddd029fc01664dfb | |
parent | d9919fb8f8539d4ddb2051735edf36dcd3b38318 (diff) | |
download | ssh2-rs-0f210fe845f36d5d6554d2adc593ec65a273f56e.zip |
Add +1 reservation for trailing zero in write_string
-rw-r--r-- | src/knownhosts.rs | 3 | ||||
-rw-r--r-- | tests/knownhosts.rs | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/src/knownhosts.rs b/src/knownhosts.rs index e8355c4..4a6c78d 100644 --- a/src/knownhosts.rs +++ b/src/knownhosts.rs @@ -117,7 +117,8 @@ impl<'sess> KnownHosts<'sess> { &mut outlen, kind as c_int); if rc == raw::LIBSSH2_ERROR_BUFFER_TOO_SMALL { - v.reserve(outlen as usize); + // + 1 for the trailing zero + v.reserve(outlen as usize + 1); } else { try!(self.sess.rc(rc)); v.set_len(outlen as usize); diff --git a/tests/knownhosts.rs b/tests/knownhosts.rs index d23d213..f3a67fd 100644 --- a/tests/knownhosts.rs +++ b/tests/knownhosts.rs @@ -35,6 +35,7 @@ CZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2R\ PW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi\ /w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="); - assert_eq!(hosts.write_string(&host, KnownHostFileKind::OpenSSH).unwrap(), encoded); + assert_eq!(hosts.write_string(&host, KnownHostFileKind::OpenSSH).unwrap(), + encoded); hosts.remove(host).unwrap(); } |