When connecting as root, the "hostsfile" variable would be NULL due to
the code leading to this point. This would result into a crash when
attempting to set the known hosts file path.
To avoid deviating from the approach taken in the libssh2 driver set the
file to /dev/null so that all entries are discarded unless explicitly
specified.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1406457
---
Note that it would be much simpler just to skip ssh_options_set if 'hostsfile'
is NULL. This would result in using /root/.ssh/known_hosts (according to the
config) which would be different to the approach taken in libssh2. With libssh2
this can't be done (at least the last time I checked) as it happened to corrupt
the file in some cases.
src/rpc/virnetlibsshsession.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 5de6629d7..5fc16ba8a 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -1172,6 +1172,9 @@ virNetLibsshSessionSetHostKeyVerification(virNetLibsshSessionPtr
sess,
goto error;
}
+ if (!hostsfile)
+ hostsfile = "/dev/null";
+
/* set the known hosts file */
if (ssh_options_set(sess->session, SSH_OPTIONS_KNOWNHOSTS, hostsfile) < 0)
goto error;
--
2.11.0