]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
eliminated some memory leaks caused by DHE and RSA-EXPORT ciphersuites. Thanks to...
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 19 Mar 2005 14:24:44 +0000 (14:24 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 19 Mar 2005 14:24:44 +0000 (14:24 +0000)
lib/auth_cert.c
lib/auth_cert.h
lib/auth_dh_common.c
lib/auth_dh_common.h
lib/gnutls_auth.c
lib/gnutls_record.c
lib/gnutls_session_pack.c

index 98c6a36f288c8fa0e6975f6436488728d27305e2..81a183a3b99554fbfcd541e008a0e6f20e31abec 100644 (file)
@@ -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);
+}
+
index 1a0d91cf1b88ac0119f412ef8f482c3ee9649b34..ccf21ea65450a939be7811cb01d6542c0c2f90ed 100644 (file)
@@ -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 **);
index 7389bee4db6620bd05023bb00feb40a6e428538b..a1ec0dd3e18f6f7b5085926fde4f3c87d26f3746 100644 (file)
 #include <gnutls_state.h>
 #include <auth_dh_common.h>
 
+/* 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)
index b721199c1b9efe7832ebb34af3c95ed38470eb88..2a643df557c7dfb3b5f19234164f8b14c4d598ec 100644 (file)
@@ -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,
index c14eea7b388c22436a5a2320474f25310455e656..a4cfb646e8e41fa7bb8262fb3738960bdce92d69 100644 (file)
@@ -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);
        }
 
 
index 1317d008307f6265bd554008d1b01de7bd165542..bdd8dbb2c35dbf804937c26453429d92d3c34a28 100644 (file)
@@ -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
index 30a9c97f3063681a379ef50af4580966c3eb1abf..2ff8d089aa058b40d7cd05a85809869a07dd18ca 100644 (file)
@@ -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));