[evolution] store_info_insert_folder_info: Use g_hash_table_replace() to avoid use-after-free



commit 26e359645f68583ac2d851e577f37df593056fa4
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jun 25 19:02:52 2014 +0200

    store_info_insert_folder_info: Use g_hash_table_replace() to avoid use-after-free
    
    The previously used g_hash_table_insert() replaces only value for keys
    which are already included in the hash table, but as the key is owned
    by the value and freed together with the value, then here should
    be used g_hash_table_replace(), which replaces both key and value,
    thus avoids the use-after-free on the hash table's key.

 libemail-engine/mail-folder-cache.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
---
diff --git a/libemail-engine/mail-folder-cache.c b/libemail-engine/mail-folder-cache.c
index d6bb1e5..f5d49a3 100644
--- a/libemail-engine/mail-folder-cache.c
+++ b/libemail-engine/mail-folder-cache.c
@@ -386,7 +386,8 @@ store_info_insert_folder_info (StoreInfo *store_info,
 
        folder_info_ht = store_info->folder_info_ht;
 
-       g_hash_table_insert (
+       /* Replace both key and value, because the key gets freed as soon as the value */
+       g_hash_table_replace (
                folder_info_ht,
                folder_info->full_name,
                folder_info_ref (folder_info));


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