]> xenbits.xensource.com Git - libvirt.git/commitdiff
fix OOM handling in hash routines
authorChristophe Fergeau <teuf@gnome.org>
Mon, 14 Feb 2011 05:36:06 +0000 (13:36 +0800)
committerDaniel Veillard <veillard@redhat.com>
Mon, 14 Feb 2011 05:36:06 +0000 (13:36 +0800)
* src/util/hash.c: virHashAddEntry and virHashUpdateEntry were missing NULL
  checks on strdup
* AUTHORS: add Christophe Fergeau

AUTHORS
src/util/hash.c

diff --git a/AUTHORS b/AUTHORS
index 38ea4bb51ec81484644b52c79f5dffcdd43eeca3..6ff7c14c20c6478264104ee91543d289b52bf841 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -154,6 +154,7 @@ Patches have also been contributed by:
   Zdenek Styblik       <stybla@turnovfree.net>
   Gui Jianfeng         <guijianfeng@cn.fujitsu.com>
   Michal Novotny       <minovotn@redhat.com>
+  Christophe Fergeau   <teuf@gnome.org>
 
   [....send patches to get your name here....]
 
index 5c56dae02995b84ddd57231ac0f99e7b7a069ff3..754a87687c1f05cb2023908de18134cada4da65b 100644 (file)
@@ -253,6 +253,7 @@ virHashAddEntry(virHashTablePtr table, const char *name, void *userdata)
     unsigned long key, len = 0;
     virHashEntryPtr entry;
     virHashEntryPtr insert;
+    char *new_name;
 
     if ((table == NULL) || (name == NULL))
         return (-1);
@@ -281,12 +282,17 @@ virHashAddEntry(virHashTablePtr table, const char *name, void *userdata)
             return (-1);
     }
 
-    entry->name = strdup(name);
+    new_name = strdup(name);
+    if (new_name == NULL) {
+        if (insert != NULL)
+            VIR_FREE(entry);
+        return (-1);
+    }
+    entry->name = new_name;
     entry->payload = userdata;
     entry->next = NULL;
     entry->valid = 1;
 
-
     if (insert != NULL)
         insert->next = entry;
 
@@ -318,6 +324,7 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
     unsigned long key;
     virHashEntryPtr entry;
     virHashEntryPtr insert;
+    char *new_name;
 
     if ((table == NULL) || name == NULL)
         return (-1);
@@ -353,7 +360,13 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
             return (-1);
     }
 
-    entry->name = strdup(name);
+    new_name= strdup(name);
+    if (new_name == NULL) {
+        if (insert != NULL)
+            VIR_FREE(entry);
+        return (-1);
+    }
+    entry->name = new_name;
     entry->payload = userdata;
     entry->next = NULL;
     entry->valid = 1;