[Libvirt-cim] [PATCH] (#2) Make virt_device_dup() not crash the CIMOM if a field is NULL

Dan Smith danms at us.ibm.com
Tue Jan 22 20:07:07 UTC 2008


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1201036025 28800
# Node ID 93454e6c0dfe66eedc679e8f839b523991ad3b10
# Parent  84f80a8040eb29109d0fce50b582582527c2e50e
(#2) Make virt_device_dup() not crash the CIMOM if a field is NULL

Changes since last time:
- Clear the new device so we don't leave garbage if the source
  has a NULL field

Signed-off-by: Dan Smith <danms at us.ibm.com>

diff -r 84f80a8040eb -r 93454e6c0dfe libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c	Tue Jan 22 11:22:14 2008 -0800
+++ b/libxkutil/device_parsing.c	Tue Jan 22 13:07:05 2008 -0800
@@ -519,13 +519,16 @@ static int parse_devices(const char *xml
         return count;
 }
 
-#define DUP_FIELD(d, s, f) ((d)->f = strdup((s)->f))
+#define DUP_FIELD(d, s, f) do {                         \
+                if ((s)->f != NULL)                     \
+                        (d)->f = strdup((s)->f);        \
+        } while (0);
 
 struct virt_device *virt_device_dup(struct virt_device *_dev)
 {
         struct virt_device *dev;
 
-        dev = malloc(sizeof(*dev));
+        dev = calloc(1, sizeof(*dev));
         if (dev == NULL)
                 return NULL;
 




More information about the Libvirt-cim mailing list