summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-07-21 14:07:23 +0200
committerAndreas Schneider <mail@cynapses.org>2009-07-23 09:07:26 +0200
commitb07ec7a3d125bd17f7769e471fe82e9a7aba22bf (patch)
tree642f973b8e5aed6b80d23e3c64fcf94cb25d148b
parent09d4029ac1b7ff087380ff41e93515a12ad7ab1f (diff)
downloadlibssh-b07ec7a3d125bd17f7769e471fe82e9a7aba22bf.tar.gz
libssh-b07ec7a3d125bd17f7769e471fe82e9a7aba22bf.tar.xz
libssh-b07ec7a3d125bd17f7769e471fe82e9a7aba22bf.zip
Fix ssh_write_knownhost() which always returned -1.
fwrite() return the the number of items written not the size of the buffer.
-rw-r--r--libssh/keyfiles.c2
-rw-r--r--sample.c8
2 files changed, 6 insertions, 4 deletions
diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c
index f944e818..ad456cdf 100644
--- a/libssh/keyfiles.c
+++ b/libssh/keyfiles.c
@@ -1576,7 +1576,7 @@ int ssh_write_knownhost(SSH_SESSION *session) {
}
len = strlen(buffer);
- if (fwrite(buffer, len, 1, file) != len || ferror(file)) {
+ if (fwrite(buffer, len, 1, file) != 1 || ferror(file)) {
fclose(file);
return -1;
}
diff --git a/sample.c b/sample.c
index 85ea7d19..e2036914 100644
--- a/sample.c
+++ b/sample.c
@@ -476,7 +476,6 @@ int main(int argc, char **argv){
/* fallback to SSH_SERVER_NOT_KNOWN behaviour */
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;