
On Sun, Feb 13, 2011 at 10:45:18PM +0100, Christophe Fergeau wrote:
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;
Okay, I commited that one, there was just a lack of declaration for new_name in virHashUpdateEntry, but the 2 routines had to be fixed, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/