WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] libxl: correct allocation size in libxl_list_vm

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] libxl: correct allocation size in libxl_list_vm
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Fri, 15 Jul 2011 14:03:20 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Fri, 15 Jul 2011 06:05:30 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1310734995 -3600
# Node ID 89074871f15c01c9c6447d8e1814f0b6d0abe592
# Parent  ebbd0497524ac8ef7c03864d95a91c4a9ecf2280
libxl: correct allocation size in libxl_list_vm

*ptr has type libxl_vminfo not libxl_domid, so correct calloc call.

This the second instance of this bug I've noticed recently, I did a
quick audit of other similar uses of sizeof(...) and all I spotted
were a couple of harmlessly reversed calloc arguments. It's a pretty
strong argument for "foo = ..alloc(sizeof(*foo))" rather than
"alloc(sizeof(foos_type))" though...

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r ebbd0497524a -r 89074871f15c tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Fri Jul 15 13:29:53 2011 +0100
+++ b/tools/libxl/libxl.c       Fri Jul 15 14:03:15 2011 +0100
@@ -449,7 +449,7 @@ libxl_vminfo * libxl_list_vm(libxl_ctx *
     xc_domaininfo_t info[1024];
     int size = 1024;
 
-    ptr = calloc(size, sizeof(libxl_dominfo));
+    ptr = calloc(size, sizeof(libxl_vminfo));
     if (!ptr)
         return NULL;
 
diff -r ebbd0497524a -r 89074871f15c tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c    Fri Jul 15 13:29:53 2011 +0100
+++ b/tools/libxl/libxl_dm.c    Fri Jul 15 14:03:15 2011 +0100
@@ -757,7 +757,7 @@ retry_transaction:
     libxl_domain_unpause(ctx, domid);
 
     if (starting_r) {
-        *starting_r = calloc(sizeof(libxl__device_model_starting), 1);
+        *starting_r = calloc(1, sizeof(libxl__device_model_starting));
         (*starting_r)->domid = info->domid;
         (*starting_r)->dom_path = libxl__xs_get_dompath(gc, info->domid);
         (*starting_r)->for_spawn = NULL;
@@ -834,11 +834,11 @@ int libxl__create_device_model(libxl__gc
 
     if (starting_r) {
         rc = ERROR_NOMEM;
-        *starting_r = calloc(sizeof(libxl__device_model_starting), 1);
+        *starting_r = calloc(1, sizeof(libxl__device_model_starting));
         if (!*starting_r)
             goto out_close;
         p = *starting_r;
-        p->for_spawn = calloc(sizeof(libxl__spawn_starting), 1);
+        p->for_spawn = calloc(1, sizeof(libxl__spawn_starting));
     } else {
         p = &buf_starting;
         p->for_spawn = NULL;

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] libxl: correct allocation size in libxl_list_vm, Ian Campbell <=