[evolution-mapi] Call OpenProfile() with talloc-allocated 'profile' parameter



commit 0f1031807f309e6d74193124977812236a7e138c
Author: Milan Crha <mcrha redhat com>
Date:   Thu Feb 14 19:03:25 2013 +0100

    Call OpenProfile() with talloc-allocated 'profile' parameter
    
    The 'profile' variable have been allocated on stack, but the underlying
    code could expect a talloc-allocated memory, which could cause crashes
    during connection to the server in this function.

 src/libexchangemapi/e-mapi-connection.c |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/src/libexchangemapi/e-mapi-connection.c b/src/libexchangemapi/e-mapi-connection.c
index 806bc45..121a5ea 100644
--- a/src/libexchangemapi/e-mapi-connection.c
+++ b/src/libexchangemapi/e-mapi-connection.c
@@ -760,12 +760,15 @@ e_mapi_connection_connected (EMapiConnection *conn)
 
        res = priv->session != NULL;
        if (res) {
-               struct mapi_profile profile = { 0 };
+               struct mapi_profile *profile;
 
-               if (MAPI_E_SUCCESS == OpenProfile (priv->mapi_ctx, &profile, priv->profile, NULL)) {
-                       res = can_reach_mapi_server (profile.server, NULL, perror);
-                       ShutDown (&profile);
+               profile = talloc_zero (priv->mapi_ctx, struct mapi_profile);
+               if (MAPI_E_SUCCESS == OpenProfile (priv->mapi_ctx, profile, priv->profile, NULL)) {
+                       res = can_reach_mapi_server (profile->server, NULL, perror);
+                       ShutDown (profile);
                }
+
+               talloc_free (profile);
        }
 
        UNLOCK ();
@@ -6733,7 +6736,7 @@ mapi_profile_load (ESourceRegistry *registry,
 {
        enum MAPISTATUS ms = MAPI_E_SUCCESS;
        struct mapi_session *session = NULL;
-       struct mapi_profile profile = { 0 };
+       struct mapi_profile *profile;
        guint32 debug_log_level = 0;
 
        e_return_val_mapi_error_if_fail (mapi_ctx != NULL, MAPI_E_INVALID_PARAMETER, NULL);
@@ -6751,13 +6754,14 @@ mapi_profile_load (ESourceRegistry *registry,
                SetMAPIDebugLevel (mapi_ctx, debug_log_level);
        }
 
-       if (MAPI_E_SUCCESS == OpenProfile (mapi_ctx, &profile, profname, NULL)) {
-               if (!can_reach_mapi_server (profile.server, cancellable, perror)) {
-                       ShutDown (&profile);
+       profile = talloc_zero (mapi_ctx, struct mapi_profile);
+       if (MAPI_E_SUCCESS == OpenProfile (mapi_ctx, profile, profname, NULL)) {
+               if (!can_reach_mapi_server (profile->server, cancellable, perror)) {
+                       ShutDown (profile);
                        goto cleanup;
                }
 
-               ShutDown (&profile);
+               ShutDown (profile);
        }
 
        e_mapi_debug_print("Loading profile %s ", profname);
@@ -6772,6 +6776,7 @@ mapi_profile_load (ESourceRegistry *registry,
        }
 
  cleanup:
+       talloc_free (profile);
        e_mapi_utils_global_unlock ();
        e_mapi_debug_print ("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]