aboutsummaryrefslogtreecommitdiff
path: root/sample.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-07-21 14:07:23 +0200
committerAndreas Schneider <mail@cynapses.org>2009-07-21 14:07:23 +0200
commitb534bfc520282a533fabf72c36f554b035460d6d (patch)
treea43fcb14235e98944d74289ffc08e8c517d55a00 /sample.c
parent41a8fb5810759118d93bee30a254ecf4863437b5 (diff)
downloadlibssh-b534bfc520282a533fabf72c36f554b035460d6d.tar.gz
libssh-b534bfc520282a533fabf72c36f554b035460d6d.tar.xz
libssh-b534bfc520282a533fabf72c36f554b035460d6d.zip
Fix ssh_write_knownhost() which always returned -1.
fwrite() return the the number of items written not the size of the buffer.
Diffstat (limited to 'sample.c')
-rw-r--r--sample.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/sample.c b/sample.c
index fb6cf4b7..4313b6f3 100644
--- a/sample.c
+++ b/sample.c
@@ -476,7 +476,6 @@ int main(int argc, char **argv){
/* fallback to SSH_SERVER_NOT_KNOWN behavior */
case SSH_SERVER_NOT_KNOWN:
hexa = ssh_get_hexa(hash, hlen);
- free(hash);
fprintf(stderr,"The server is unknown. Do you trust the host key ?\n");
fprintf(stderr, "Public key hash: %s\n", hexa);
free(hexa);
@@ -488,8 +487,11 @@ int main(int argc, char **argv){
fprintf(stderr,"This new key will be written on disk for further usage. do you agree ?\n");
fgets(buf,sizeof(buf),stdin);
if(strncasecmp(buf,"yes",3)==0){
- if(ssh_write_knownhost(session))
- fprintf(stderr,"error %s\n",ssh_get_error(session));
+ if (ssh_write_knownhost(session) < 0) {
+ free(hash);
+ fprintf(stderr, "error %s\n", strerror(errno));
+ exit(-1);
+ }
}
break;