[PATCH 2/8] fix OOM handling in hash.c

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

 



missing NULL check on strdup
---
 src/util/hash.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/util/hash.c b/src/util/hash.c
index e102d7d..893fe96 100644
--- a/src/util/hash.c
+++ b/src/util/hash.c
@@ -254,6 +254,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);
@@ -282,12 +283,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;
 
@@ -354,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;
-- 
1.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]