diff options
author | Wez Furlong <wez@wezfurlong.org> | 2019-07-23 18:14:13 -0700 |
---|---|---|
committer | Wez Furlong <wez@wezfurlong.org> | 2019-07-29 08:55:06 -0700 |
commit | 8dde97813e5321d8307f197c1a4bee3a2a4651cb (patch) | |
tree | 2662220500db368e52eec41e997c96a1497300b2 /src | |
parent | f8967b396e7e85072d8eb39654e366c1db5f8e73 (diff) | |
download | ssh2-rs-8dde97813e5321d8307f197c1a4bee3a2a4651cb.zip |
Avoid panic when SSH_USERAUTH_NONE succeeds
This is an alternative take on addressing this issue:
Refs: https://github.com/alexcrichton/ssh2-rs/pull/104
Diffstat (limited to 'src')
-rw-r--r-- | src/session.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/session.rs b/src/session.rs index edc6898..8fa188e 100644 --- a/src/session.rs +++ b/src/session.rs @@ -361,14 +361,18 @@ impl Session { /// return an error. This case may be distinguished from a failing case by /// examining the return value of the `authenticated` method. /// - /// The return value is a comma-separated string of supported auth schemes. + /// The return value is a comma-separated string of supported auth schemes, + /// and may be an empty string. pub fn auth_methods(&self, username: &str) -> Result<&str, Error> { let len = username.len(); let username = try!(CString::new(username)); unsafe { let ret = raw::libssh2_userauth_list(self.inner.raw, username.as_ptr(), len as c_uint); if ret.is_null() { - Err(Error::last_error(self).unwrap()) + match Error::last_error(self) { + Some(err) => Err(err), + None => Ok(""), + } } else { Ok(str::from_utf8(::opt_bytes(self, ret).unwrap()).unwrap()) } |