From: Nikos Mavrogiannopoulos Date: Sat, 19 Mar 2005 14:24:44 +0000 (+0000) Subject: eliminated some memory leaks caused by DHE and RSA-EXPORT ciphersuites. Thanks to... X-Git-Tag: gnutls_1_2_1~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1a0a8967ed801bb5e44836cba79acfe4732dcfb;p=thirdparty%2Fgnutls.git eliminated some memory leaks caused by DHE and RSA-EXPORT ciphersuites. Thanks to Yoann Vandoorselaere for reporting them. --- diff --git a/lib/auth_cert.c b/lib/auth_cert.c index 98c6a36f28..81a183a3b9 100644 --- a/lib/auth_cert.c +++ b/lib/auth_cert.c @@ -1589,3 +1589,12 @@ int _gnutls_server_select_cert(gnutls_session_t session, return ret; } + +/* Frees the rsa_info_st structure. + */ +void _gnutls_free_rsa_info( rsa_info_st* rsa) +{ + _gnutls_free_datum( &rsa->modulus); + _gnutls_free_datum( &rsa->exponent); +} + diff --git a/lib/auth_cert.h b/lib/auth_cert.h index 1a0d91cf1b..ccf21ea654 100644 --- a/lib/auth_cert.h +++ b/lib/auth_cert.h @@ -142,6 +142,8 @@ typedef struct cert_auth_info_st { typedef struct cert_auth_info_st cert_auth_info_st; +void _gnutls_free_rsa_info( rsa_info_st* rsa); + /* AUTH X509 functions */ int _gnutls_gen_cert_server_certificate(gnutls_session_t, opaque **); int _gnutls_gen_cert_client_certificate(gnutls_session_t, opaque **); diff --git a/lib/auth_dh_common.c b/lib/auth_dh_common.c index 7389bee4db..a1ec0dd3e1 100644 --- a/lib/auth_dh_common.c +++ b/lib/auth_dh_common.c @@ -39,6 +39,16 @@ #include #include +/* Frees the dh_info_st structure. + */ +void _gnutls_free_dh_info( dh_info_st* dh) +{ + dh->secret_bits = 0; + _gnutls_free_datum( &dh->prime); + _gnutls_free_datum( &dh->generator); + _gnutls_free_datum( &dh->public_key); +} + int _gnutls_proc_dh_common_client_kx(gnutls_session_t session, opaque * data, size_t _data_size, mpi_t g, mpi_t p) diff --git a/lib/auth_dh_common.h b/lib/auth_dh_common.h index b721199c1b..2a643df557 100644 --- a/lib/auth_dh_common.h +++ b/lib/auth_dh_common.h @@ -33,6 +33,7 @@ typedef struct { gnutls_datum_t public_key; } dh_info_st; +void _gnutls_free_dh_info( dh_info_st* dh); int _gnutls_gen_dh_common_client_kx(gnutls_session_t, opaque **); int _gnutls_proc_dh_common_client_kx(gnutls_session_t session, opaque * data, size_t _data_size, diff --git a/lib/gnutls_auth.c b/lib/gnutls_auth.c index c14eea7b38..a4cfb646e8 100644 --- a/lib/gnutls_auth.c +++ b/lib/gnutls_auth.c @@ -270,6 +270,9 @@ void *_gnutls_get_auth_info(gnutls_session_t session) -*/ void _gnutls_free_auth_info(gnutls_session_t session) { +dh_info_st *dh_info; +rsa_info_st * rsa_info; + if (session == NULL || session->key == NULL) { gnutls_assert(); return; @@ -277,8 +280,16 @@ void _gnutls_free_auth_info(gnutls_session_t session) switch (session->key->auth_info_type) { case GNUTLS_CRD_SRP: - case GNUTLS_CRD_ANON: + break; + case GNUTLS_CRD_ANON: { + anon_auth_info_t info = _gnutls_get_auth_info(session); + + if (info == NULL) + break; + dh_info = &info->dh; + _gnutls_free_dh_info( dh_info); + } break; case GNUTLS_CRD_CERTIFICATE:{ unsigned int i; @@ -286,6 +297,9 @@ void _gnutls_free_auth_info(gnutls_session_t session) if (info == NULL) break; + + dh_info = &info->dh; + rsa_info = &info->rsa_export; for (i = 0; i < info->ncerts; i++) { _gnutls_free_datum(&info->raw_certificate_list[i]); } @@ -293,6 +307,9 @@ void _gnutls_free_auth_info(gnutls_session_t session) gnutls_free(info->raw_certificate_list); info->raw_certificate_list = NULL; info->ncerts = 0; + + _gnutls_free_dh_info( dh_info); + _gnutls_free_rsa_info( rsa_info); } diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c index 1317d00830..bdd8dbb2c3 100644 --- a/lib/gnutls_record.c +++ b/lib/gnutls_record.c @@ -986,10 +986,8 @@ ssize_t _gnutls_recv_int(gnutls_session_t session, content_type_t type, * If the EINTR is returned by the internal push function (the default is recv()) * then GNUTLS_E_INTERRUPTED will be returned. If GNUTLS_E_INTERRUPTED or * GNUTLS_E_AGAIN is returned, you must call this function again, with the - * same parameters; cf. gnutls_record_get_direction(). Alternatively - * you could provide a NULL pointer for data, and 0 for size. - * Otherwise the write operation will be corrupted and the connection - * will be terminated. + * same parameters; alternatively you could provide a NULL pointer for data, + * and 0 for size. cf. gnutls_record_get_direction(). * * Returns the number of bytes sent, or a negative error code. The number * of bytes sent might be less than @sizeofdata. The maximum number of bytes diff --git a/lib/gnutls_session_pack.c b/lib/gnutls_session_pack.c index 30a9c97f30..2ff8d089aa 100644 --- a/lib/gnutls_session_pack.c +++ b/lib/gnutls_session_pack.c @@ -255,6 +255,7 @@ int _gnutls_session_unpack(gnutls_session_t session, /* Delete the DH parameters. (this might need to be moved to a function) */ info = session->key->auth_info; + _gnutls_free_dh_info( &info->dh); memset(&info->dh, 0, sizeof(dh_info_st)); } break; @@ -403,6 +404,8 @@ int _gnutls_unpack_certificate_auth_info(cert_auth_info_t info, /* Delete the dh_info_st and rsa_info_st fields. */ + _gnutls_free_dh_info( &info->dh); + _gnutls_free_rsa_info( &info->rsa_export); memset(&info->dh, 0, sizeof(dh_info_st)); memset(&info->rsa_export, 0, sizeof(rsa_info_st));