knownhost_check(): Don't dereference ext if NULL is passed

Documentation for libssh2_knownhost_checkp() and related functions
states that the last argument is filled with data if non-NULL.

"knownhost if set to non-NULL, it must be a pointer to a 'struct
libssh2_knownhost' pointer that gets filled in to point to info about a
known host that matches or partially matches."

In this function ext is dereferenced even if set to NULL, causing
segfault in applications not needing the extra data.
This commit is contained in:
Peter Krempa 2011-11-15 11:14:39 +01:00 committed by Alexander Lamaison
parent 378311fe5b
commit fed94fa85d

View File

@ -417,7 +417,8 @@ knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
/* host name match, now compare the keys */
if(!strcmp(key, node->key)) {
/* they match! */
*ext = knownhost_to_external(node);
if (ext)
*ext = knownhost_to_external(node);
badkey = NULL;
rc = LIBSSH2_KNOWNHOST_CHECK_MATCH;
break;
@ -438,7 +439,8 @@ knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
if(badkey) {
/* key mismatch */
*ext = knownhost_to_external(badkey);
if (ext)
*ext = knownhost_to_external(badkey);
rc = LIBSSH2_KNOWNHOST_CHECK_MISMATCH;
}