From fed94fa85da30c00496c973773896b7a5615fcb0 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 15 Nov 2011 11:14:39 +0100 Subject: [PATCH] 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. --- src/knownhost.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/knownhost.c b/src/knownhost.c index d90f1d4..193bda3 100644 --- a/src/knownhost.c +++ b/src/knownhost.c @@ -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; }