From: Nikos Mavrogiannopoulos Date: Sun, 18 Apr 2004 12:11:52 +0000 (+0000) Subject: Corrected bug in OpenPGP key loading using a callback. X-Git-Tag: gnutls_1_1_11~124 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b66d53b74213216acca79ea96aebe6df08ddc1ef;p=thirdparty%2Fgnutls.git Corrected bug in OpenPGP key loading using a callback. --- diff --git a/NEWS b/NEWS index 7268d2b4f9..89c3e0fa6e 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ Version 1.1.10 - Added gnutls_sign_algorithm_get_name() and gnutls_pk_algorithm_get_name() - Corrected bug in TLS renegotiation. +- Corrected bug in OpenPGP key loading using a callback. Version 1.1.9 (14/04/2004) - Added support for authority key identifier and the extended key usage diff --git a/includes/gnutls/openpgp.h b/includes/gnutls/openpgp.h index 85d741841f..6960e1d957 100644 --- a/includes/gnutls/openpgp.h +++ b/includes/gnutls/openpgp.h @@ -31,6 +31,7 @@ extern "C" { #endif #include +#include /* gnutls_openpgp_key should be defined in gnutls.h */ diff --git a/lib/auth_cert.c b/lib/auth_cert.c index c0de1ed568..c31eea5b82 100644 --- a/lib/auth_cert.c +++ b/lib/auth_cert.c @@ -485,23 +485,27 @@ static int _select_client_cert(gnutls_session session, /* use a callback to get certificate */ - issuers_dn_length = get_issuers_num( session, data, data_size); - if (issuers_dn_length < 0) { - gnutls_assert(); - return issuers_dn_length; - } - - if (issuers_dn_length > 0) { - issuers_dn = gnutls_malloc( sizeof(gnutls_datum)*issuers_dn_length); - if (issuers_dn == NULL) { + if (session->security_parameters.cert_type != GNUTLS_CRT_X509) + issuers_dn_length = 0; + else { + issuers_dn_length = get_issuers_num( session, data, data_size); + if (issuers_dn_length < 0) { gnutls_assert(); - return GNUTLS_E_MEMORY_ERROR; + return issuers_dn_length; } + + if (issuers_dn_length > 0) { + issuers_dn = gnutls_malloc( sizeof(gnutls_datum)*issuers_dn_length); + if (issuers_dn == NULL) { + gnutls_assert(); + return GNUTLS_E_MEMORY_ERROR; + } - result = get_issuers( session, issuers_dn, issuers_dn_length, data, data_size); - if (result < 0) { - gnutls_assert(); - goto cleanup; + result = get_issuers( session, issuers_dn, issuers_dn_length, data, data_size); + if (result < 0) { + gnutls_assert(); + goto cleanup; + } } } @@ -1097,10 +1101,10 @@ int _gnutls_proc_cert_cert_req(gnutls_session session, opaque * data, size_t data_size) { int size, ret; - opaque *p = data; + opaque *p; const gnutls_certificate_credentials cred; CERTIFICATE_AUTH_INFO info; - ssize_t dsize = data_size; + ssize_t dsize; int i, j; gnutls_pk_algorithm pk_algos[MAX_SIGN_ALGOS]; int pk_algos_length; @@ -1122,6 +1126,9 @@ int _gnutls_proc_cert_cert_req(gnutls_session session, opaque * data, info = _gnutls_get_auth_info(session); + p = data; + dsize = data_size; + DECR_LEN(dsize, 1); size = p[0]; p++; @@ -1370,6 +1377,8 @@ static gnutls_cert *alloc_and_load_x509_certs(gnutls_x509_crt * certs, int ret = 0; uint i, j; + if (certs == NULL) return NULL; + local_certs = gnutls_malloc(sizeof(gnutls_cert) * ncerts); if (local_certs == NULL) { gnutls_assert(); @@ -1403,6 +1412,8 @@ static gnutls_privkey *alloc_and_load_x509_key(gnutls_x509_privkey key) gnutls_privkey *local_key; int ret = 0; + if (key == NULL) return NULL; + local_key = gnutls_malloc(sizeof(gnutls_privkey)); if (local_key == NULL) { gnutls_assert(); @@ -1430,7 +1441,8 @@ static gnutls_cert *alloc_and_load_pgp_certs(gnutls_openpgp_key cert) { gnutls_cert *local_certs; int ret = 0; - uint i, j; + + if (cert == NULL) return NULL; local_certs = gnutls_malloc(sizeof(gnutls_cert)); if (local_certs == NULL) { @@ -1443,7 +1455,7 @@ static gnutls_cert *alloc_and_load_pgp_certs(gnutls_openpgp_key cert) return NULL; } - ret = _E_gnutls_openpgp_key_to_gcert(&local_certs[i], cert); + ret = _E_gnutls_openpgp_key_to_gcert(local_certs, cert); if (ret < 0) { gnutls_assert(); return NULL; @@ -1451,9 +1463,7 @@ static gnutls_cert *alloc_and_load_pgp_certs(gnutls_openpgp_key cert) if (ret < 0) { gnutls_assert(); - for (j = 0; j < i; j++) { - _gnutls_gcert_deinit(&local_certs[j]); - } + _gnutls_gcert_deinit(local_certs); gnutls_free(local_certs); return NULL; } @@ -1469,6 +1479,8 @@ static gnutls_privkey *alloc_and_load_pgp_key(const gnutls_openpgp_privkey key) gnutls_privkey *local_key; int ret = 0; + if (key == NULL) return NULL; + local_key = gnutls_malloc(sizeof(gnutls_privkey)); if (local_key == NULL) { gnutls_assert();