Fix segfault with gcrypt.

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@542 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-18 10:53:28 +00:00
parent fa01372c88
commit d20ae18b00
2 changed files with 14 additions and 7 deletions

View File

@@ -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) {

View File

@@ -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;