After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 731218 - fix memory corruption in rest_params_add
fix memory corruption in rest_params_add
Status: RESOLVED DUPLICATE of bug 665716
Product: librest
Classification: Platform
Component: other
git master
Other Linux
: Normal normal
: ---
Assigned To: librest-maint
librest-maint
Depends on:
Blocks:
 
 
Reported: 2014-06-04 15:11 UTC by Christophe Fergeau
Modified: 2014-06-27 16:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Use g_hash_table_replace() in rest_params_add() (1.78 KB, patch)
2014-06-04 15:11 UTC, Christophe Fergeau
none Details | Review

Description Christophe Fergeau 2014-06-04 15:11:42 UTC
Created attachment 277884 [details] [review]
Use g_hash_table_replace() in rest_params_add()

Use g_hash_table_replace() in rest_params_add()
    
    rest_params_add() is currently using g_hash_table_insert() to add
    the passed in parameter in the parameter hash table. The key which
    is used is owned by the associated value.
    
    When using rest_params_add to replace an already existing parameter,
    the existing value will be freed with rest_param_unref().
    
    However, g_hash_table_insert() does not replace the key when it already
    exists in the hash table: "If the key already exists in the GHashTable
    its current value is replaced with the new value... If you supplied a
    key_destroy_func when creating the GHashTable, the passed key is freed
    using that function."
    
    This means that after replacing an already existing parameter, the
    corresponding key will still be the old one, which is now pointing
    at freed memory as the old value was freed.
    
    g_hash_table_replace() ensures that the key will still be valid, even
    when replacing existing parameters:
    "Inserts a new key and value into a GHashTable similar to
    g_hash_table_insert(). The difference is that if the key already exists
    in the GHashTable, it gets replaced by the new key."
Comment 1 Christophe Fergeau 2014-06-27 16:54:15 UTC

*** This bug has been marked as a duplicate of bug 665716 ***