Skip to contentSkip to conversation

libxl: avoid double free of b_info->u.pv.bootloader

PATCH In review Ian Campbell 1 participant 2 messages May 18, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libxl: avoid double free of b_info->u.pv.bootloader

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1337335831 -3600
# Node ID 894f39993bdc96aaaf2ad0115af2f5e83d9cc1b1 # Parent 0e1d32df5b8d8bdbf88b6cd4a6b18fc008258373
libxl: avoid double free of b_info->u.pv.bootloader.

b_info is a user provided struct and therefore the content must come from malloc and not gc such that libxl_domain_build_info_dispose can free it. This was broken by 25340:373f24c87dee.

---
v2: use libxl__strdup(NULL, ...) to get the expected error handling.

tools/libxl/libxl_bootloader.c +4 -2
diff -r 0e1d32df5b8d -r 894f39993bdc tools/libxl/libxl_bootloader.c
@@ -356,8 +356,10 @@ void libxl__bootloader_run(libxl__egc *e
         if ( lstat(bootloader, &st) )
             LOG(DEBUG, "%s doesn't exist, falling back to config path",
                 bootloader);
-        else
-            info->u.pv.bootloader = bootloader;
+        else {
+            free(info->u.pv.bootloader);
+            info->u.pv.bootloader = libxl__strdup(NULL, bootloader);
+        }
     }
 
     make_bootloader_args(gc, bl);
#1 lore raw
Quoted 7 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1337335831 -3600
# Node ID 894f39993bdc96aaaf2ad0115af2f5e83d9cc1b1 # Parent 0e1d32df5b8d8bdbf88b6cd4a6b18fc008258373
libxl: avoid double free of b_info->u.pv.bootloader.

Quoted 5 lines

b_info is a user provided struct and therefore the content must come from malloc and not gc such that libxl_domain_build_info_dispose can free it. This was broken by 25340:373f24c87dee.

Ian Jackson acked this out of band and I have therefore applied it.

Quoted 24 lines

---
v2: use libxl__strdup(NULL, ...) to get the expected error handling.

diff -r 0e1d32df5b8d -r 894f39993bdc tools/libxl/libxl_bootloader.c

tools/libxl/libxl_bootloader.c +4 -2
@@ -356,8 +356,10 @@ void libxl__bootloader_run(libxl__egc *e
         if ( lstat(bootloader, &st) )
             LOG(DEBUG, "%s doesn't exist, falling back to config path",
                 bootloader);
-        else
-            info->u.pv.bootloader = bootloader;
+        else {
+            free(info->u.pv.bootloader);
+            info->u.pv.bootloader = libxl__strdup(NULL, bootloader);
+        }
     }
 
     make_bootloader_args(gc, bl);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel