summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-18 10:53:28 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-18 10:53:28 +0000
commitd20ae18b00e8926df925167a2a63234f654e3817 (patch)
tree8dc8f259e1c540a6b64daea24a26509ac5d6ded3
parentfa01372c88b36378afb25c36bb080282989dd2d4 (diff)
downloadlibssh-d20ae18b00e8926df925167a2a63234f654e3817.tar.gz
libssh-d20ae18b00e8926df925167a2a63234f654e3817.tar.xz
libssh-d20ae18b00e8926df925167a2a63234f654e3817.zip
Fix segfault with gcrypt.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@542 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r--libssh/keyfiles.c8
-rw-r--r--libssh/keys.c13
2 files changed, 14 insertions, 7 deletions
diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c
index 22ead29..b23e445 100644
--- a/libssh/keyfiles.c
+++ b/libssh/keyfiles.c
@@ -32,6 +32,7 @@
#include <fcntl.h>
#include <ctype.h>
#include "libssh/priv.h"
+
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
#elif defined HAVE_LIBCRYPTO
@@ -39,9 +40,12 @@
#include <openssl/dsa.h>
#include <openssl/err.h>
#include <openssl/rsa.h>
-#endif
+#endif /* HAVE_LIBCRYPTO */
+
#define MAXLINESIZE 80
+
#ifdef HAVE_LIBGCRYPT
+
#define MAX_KEY_SIZE 32
#define MAX_PASSPHRASE_SIZE 1024
#define RSA_HEADER_BEGIN "-----BEGIN RSA PRIVATE KEY-----"
@@ -462,7 +466,7 @@ static int read_dsa_privatekey(FILE *fp, gcry_sexp_t *r, ssh_auth_callback cb,
free(v);
return 1;
}
-#endif /* GCRYPT */
+#endif /* HAVE_LIBGCRYPT */
#ifdef HAVE_LIBCRYPTO
static int pem_get_password(char *buf, int size, int rwflag, void *userdata) {
diff --git a/libssh/keys.c b/libssh/keys.c
index 4a5a25e..039f8f1 100644
--- a/libssh/keys.c
+++ b/libssh/keys.c
@@ -626,7 +626,6 @@ static int rsa_public_to_string(RSA *key, BUFFER *buffer) {
goto error;
}
string_fill(e, (char *) tmp, size);
- gcry_sexp_release(sexp);
#elif defined HAVE_LIBCRYPTO
e = make_bignum_string(key->e);
@@ -676,16 +675,20 @@ STRING *publickey_to_string(PUBLIC_KEY *key) {
if (type == NULL) {
goto error;
}
- buffer_add_ssh_string(buf, type);
+
+ if (buffer_add_ssh_string(buf, type) < 0) {
+ goto error;
+ }
+
switch(key->type){
case TYPE_DSS:
- if (dsa_public_to_string(key->dsa_pub,buf) < 0) {
+ if (dsa_public_to_string(key->dsa_pub, buf) < 0) {
goto error;
}
break;
case TYPE_RSA:
case TYPE_RSA1:
- if (rsa_public_to_string(key->rsa_pub,buf) < 0) {
+ if (rsa_public_to_string(key->rsa_pub, buf) < 0) {
goto error;
}
break;
@@ -1257,7 +1260,7 @@ STRING *ssh_do_sign(SSH_SESSION *session, BUFFER *sigbuf,
STRING *ssh_encrypt_rsa1(SSH_SESSION *session, STRING *data, PUBLIC_KEY *key) {
STRING *str = NULL;
size_t len = string_len(data);
- int size = 0;
+ size_t size = 0;
#ifdef HAVE_LIBGCRYPT
const char *tmp = NULL;
gcry_sexp_t ret_sexp;